I was new to the web application. my issue: how to pass the same parameter from one JSP to two servlets? Then pass the different parameters from servlet to the same JSP?
important!! we should do the process A first then do the process B!!!!
As the project takes too many processes, I would like to separate the processes into two servlet.
Currently, I finish implement processA which is pass the search term from SEARCH PAGE JSP to SERVLET A (do the processA) and pass the result to WELCOME PAGE JSP. It works!!!(which i highlight in the red color in the picture)
the code I used: Web.xml
<servlet>
<servlet-name>ServletA</servlet-name>
<servlet-class>test.processA</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletA</servlet-name>
<url-pattern>/download result</url-pattern>
</servlet-mapping>
Search page JSP:
<form action="download result">
Please enter a Keyword <br>
<input type="text" name="term"size="20px">
<input type="submit" value="submit">
</form>
servletA:
public class processA extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
// reading the user input
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
// Retrieve search term from GET request and parse to desired format
String searchTerm = (request.getParameter("term").toString()).replace("%20", "_").replace(" ", "_").replace("+", "_").replace(".", "");
System.out.println("=====(servlet) searchTerm is:"+searchTerm);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doGet(request, response);
}
}
So how to implement the processB into the system??? which will look like the picture i showed.
the servletB
public class processB extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String searchTerm = (request.getParameter("term")).replace(" ", "_");
String queryTerm = request.getParameter("term");
System.out.println("=====(servlet) searchTerm is:"+searchTerm);
System.out.println("=====(servlet) keep doing the other process……………………!!!”);
}
}
thanks so much! or if the doGET and doPOST cannot be used at the same time, I can change the processA to doPost.
important!! we should do the process A first then do the process B!!!!