How can I call a servlet from a JSP page? How can I pass variables from the JSP that the servlet can access?

Priya Venkatesan

You can use <jsp:forward page="/relativepath/YourServlet" /> or response.sendRedirect("http://path/YourServlet").

Variables can be sent as:

<jsp:forward page=/relativepath/YourServlet>
<jsp:param name="name1" value="value1" />
<jsp:param name="name2" value="value2" />

You may also pass parameters to your servlet by specifying response.sendRedirect("http://path/YourServlet?param1=val1").

See also: