Request parameters (post and get methods), requestget
Code for submitting a form:
<! DOCTYPE html>
Servlet code:
The package request obtains the Post or get parameters. import java. io. IOException; import java. util. arrays; import java. util. enumeration; import java. util. iterator; import java. util. map; import javax. servlet. servletException; import javax. servlet. annotation. webServlet; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse;/** demonstrate request Parameters */@ WebServle T ("/AAServlet") public class AAServlet extends HttpServlet {private static final long serialVersionUID = 1L; protected void doGet (HttpServletRequest request, response) throws ServletException, IOException {System. out. println ("get:" + request. getParameter ("xxx"); System. out. println ("get:" + request. getParameter ("yyy");} protected void doPost (HttpServletRequest request, HttpServletRespon Se response) throws ServletException, IOException {request. setCharacterEncoding ("UTF-8"); response. setContentType ("text/html; charset = UTF-8"); String username = request. getParameter ("username"); String password = request. getParameter ("password"); String [] Hober = request. getParameterValues ("holobby"); System. out. println (username + "," + password + "," + Arrays. toString (holobby);/** test to obtain the names of all request parameters */Enumeration <?> Names2 = request. getParameterNames (); while (names2.hasMoreElements () {System. out. println (names2.nextElement ();} // Iterator <String> names = (Iterator <String>) request. getParameterNames (); // while (names. hasNext () {// System. out. println (names. next (); //}/** get all request parameters and encapsulate them in Map */Map <String, String []> map = (Map <String, string []>) request. getParameterMap (); for (String name: map. keySet () {String [] values = map. get (name); System. out. println (name + "=" + Arrays. toString (values ));}}}
The above is all the content of the implementation method (post and get) for obtaining parameters in the request provided by xiaobian. I hope it will be helpful to you and support more customers ~