In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use JavaWeb to achieve form submission, the article is very detailed, has a certain reference value, interested friends must read it!
Register.htmlregister.html registration form user name: password: please choose the research direction you are interested in: artificial intelligence machine Learn network security for autopilot
RegisterServlet.javapackage request;import java.io.IOException;import java.io.PrintWriter;import java.util.Arrays;import java.util.Enumeration;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse Public class RegisterServlet extends HttpServlet {/ / call out doGet method protected void doGet (HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {/ / use req to receive request parameter String strName=req.getParameter ("username"); / / deal with Chinese miscommunication problem byte [] bs=strName.getBytes ("iso8859-1") String name=new String (bs, "utf-8"); System.out.println (name);} / call out the doPost method protected void doPost (HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {/ / set the encoding req.setCharacterEncoding ("utf-8") in the request parameters / / use req to receive request parameters String strName=req.getParameter ("username"); System.out.println ("strName");} / / call out service method protected void service (HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {PrintWriter pw=response.getWriter () System.out.println ("Registration...") / / 1. Get the full path of the request sent by the browser; StringBuffer sbuf=request.getRequestURL (); pw.println ("url:" + sbuf); / / System.out.println (sbuf); / / 2. Get the resource name part-address after 8080 in the request path; String uri=request.getRequestURI (); pw.println ("uri:" + uri); / / 3. Get the parameters in the request path; String qs=request.getQueryString (); pw.println ("qs:" + qs); / / 4. Get the ip address in the request path; String ip=request.getRemoteAddr (); pw.println ("ip:" + ip); / / ip=127.0.0.1 / / 5. Get the way the browser sends the request (get request, post request) / / on the browser side, the default way for the browser address bar to enter, hyperlink, and form is get request method / / on the browser side, the form setting method= "post" is submitted by post request method String method=request.getMethod (); pw.println ("method=" + method) / / method=GET / / 6. Get the web application name String cp=request.getContextPath (); pw.println ("cp=" + cp); / / cp=/servlet / / receive the parameters sent from the form submission / / get a single value String strName=request.getParameter ("username"); String strPwd=request.getParameter ("pwd") Pw.println ("Name:" + strName+ "Pwd:" + strPwd); / / get multiple corresponding value values String [] strInterest=request.getParameterValues ("interest"); pw.println (Arrays.toString (strInterest)); / / get all the name values in the request parameters Enumeration names=request.getAttributeNames () Pw.println (names); / / use a loop to pull out the contents of names while (names.hasMoreElements ()) {System.out.println (names.nextElement ());}
Modify the web.xml and add the following code
RegisterServlet request.RegisterServlet RegisterServlet / register reconfigure the server by clicking the icon on the left
Click Redeploy again to redeploy the Tomcat server
The above is all the content of the article "how to use JavaWeb to implement form submission". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.