This is a good example, to clean up: This article mainly describes how the servlet in the JSP page to pass the value, this example is divided into three parts of the value, 1 incoming normal string 2 incoming normal list 3 pass the list with more than one map, the page to the value passed through Jstl and El expressions to handle.
1. Start Page jspservletjstl.jsp-----jsp page for display
<%@ page contenttype= "Text/html;charset=utf-8" iserrorpage= "true"%>
2. The web.xml configuration -------web.xml file includes:<context-param> used to configure container (TOMCAT) initialization parameters. <servlet> configures the association of the servlet name with the class, and the content that the servlet handles. Listener Configure the container to respond to events, such as Org.springframework.web.util.IntrospectorCleanupListener
<!--JSP and JSTL test -->
<servlet>
<servlet-name>gojstl</servlet-name>
< Servlet-class>second. Location of the gojstl</servlet-class>//class
</servlet>
<servlet-mapping>
<servlet-name> gojstl</servlet-name>
<url-pattern>/gojstl</url-pattern> //handling access requests
to/GOJSTL paths </servlet-mapping>
3. servlet class processing ---------servlet consists of two methods, Doget and Dopost. The container chooses which method to use depending on the form, and the request for Get and post is not stated. On the difference between GetParameter and getattribute click Open Link. On the difference between forward and sendredirect see Click to open Link
Package second;
Import java.io.IOException;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
public class Gojstl extends HttpServlet {public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {doPost (request,response); public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException
{request.setcharacterencoding ("UTF-8");
String username = request.getparameter ("username");
Request.setattribute ("username", username);//write string parameter Map map1 = new HashMap () to the session;
Map1.put ("username", username+1);
Map1.put ("Idcard", "111111111111111111");
Map map2 = new HashMap ();
Map2.put ("username", username+2); Map2.put("Idcard", "2222222222222222222");
List List1 = new ArrayList ();
List1.add (MAP1);
List1.add (MAP2);
List list2 = new ArrayList ();
List2.add ("Map1");
List2.add ("Map2");
Request.setattribute ("Pagelist1", List1); Request.setattribute ("Pagelist2", List2)//Similarly, write list Parameters This.getservletcontext (). Getrequestdispatcher ("/
Showresult.jsp "). Forward (request, response);//page Jump//response.sendredirect (" finish.jsp "); }
}
4. Display processing page showresult.jsp----------Jstl is a JSP tag library, to facilitate the preparation of JSP files.
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "%>
<%@ taglib prefix=" C "uri=" Http://java.sun.com/jsp/jstl/core "%>