forse fai un po' di confusione su come risponda una servlet a chiamata: ti faccio un esempio banale ma che forse ti indirizzerà sulla "giusta" strada:
JSP
codice:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page - 2 Forms Test</h1>
<h2>GET FORM</h2>
<form name="getform" action="testservlet" method="get">
<input type="text" name="form_field_get" />
<input type="submit" value="SUBMIT" />
</form>
</p>
<h2>POST FORM</h2>
<form name="postform" action="testservlet" method="post">
<input type="text" name="form_field_post" />
<input type="submit" value="SUBMIT" />
</form>
</body>
</html>
SERVLET
codice:
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testservlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/html");
try {
PrintWriter out = res.getWriter();
out.write("<html><body><h1>GET</h1>"+req.getParameter("form_field_get")+"</body></html>");
}
catch (Exception e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/html");
try {
PrintWriter out = res.getWriter();
out.write("<html><body><h1>POST</h1>"+req.getParameter("form_field_post")+"</body></html>");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Chiaramente da mappare opportunamente nel tuo web.xml
Comunque il succo del discorso è che la JSP ha due form con method diversi (get e post) e come puoi vedere stessa action, ossia la servlet, la quale distingue il method ed esegue il codice in doGet e doPost. Quindi nel tuo doGet o doPost, a seconda del method del tuo form (o del modo in cui costruisci la query string del browser - quindi sicuramente in doGet) andrai a scrivere il codice necessario.