servlet implementation of data transmission and garbled solution

Source: Internet
Author: User

Implement a form that jumps from a JSP page to Servlet2,servlet2 jumps to Servlet3,servlet3 to get the input parameters:
Jsp:

Xml

Servlet2:

Servlet3:

wherein, in using Method 1:
Response.sendredirect ("Servlet3"), you can only implement jumps from Servlet2 to Servlet3,
It is not possible to pass the values of username and password.
In Use Method 2:
RequestDispatcher rd=request.getrequestdispatcher ("Servlet3");
Rd.forword (Request,response);
You can implement a servlet jump, and if you want to pass in a parameter, you must also have a Servlet3
String Username=request.getparameter ("username", username);
String password=request.getparameter ("password", password);
This can be achieved by HttpSession accept parameters
In the Servlet2:
HttpSession session=request.getsession ();
Session.setattribute ("username") can pass data into
In the Servlet3:
Receive with Session.getattribute ("username")
Note, however, that the resulting object is to be converted to a string type

 解决中文乱码的问题:   输入有中文:      request.setCharacterEncoding("utf-8");   输出有中文:      response.setCharacterEncoding("uft-8");      response.setContentType("text/html;charset=utf-8");

servlet implementation of data transmission and garbled solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.