Tutorials4u.net Forum

Full Version: Get parameters passed to a servlet
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
<FORM METHOD=POST ACTION="/servlet/MyServlet">
value : <INPUT TYPE="TEXT" NAME="someValue">

import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res) {
// note : if "someValue" is missing a null is returned
String valuePassed = req.getParameter("someValue");

java.io.PrintWriter out = res.getWriter();
out.println("the value is : " + valuePassed);

public void doGet(HttpServletRequest req, HttpServletResponse res) {
doPost(req, res);

Reference URL's