Implemented using registration request object instance, request method

 

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.Date" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <form action="register.jsp">
    用户名:<input type="text" name="uname"/><br/>
    密码:<input type="password" name="upwd"/><br/>
    <input type="submit" value="submit">
  </form>
  </body>
</html>

register.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    //设置编码
    request.setCharacterEncoding("utf-8");
    String name=request.getParameter("uname");
    String pwd=request.getParameter("upwd");
%>
注册成功!信息如下!
<br/>
姓名:<%=name %>
</body>
</html>

You can also change the form information by modifying the address bar

http://localhost:8080/untitled_war_exploded/register.jsp?uname=2&upwd=1

                       Connection / file? Parameter name parameter value = 1 1 = 2 Parameter Name Parameter Value & 2

get submission : method = "get" request and the address bar by default are all ways get submission

The difference between the way get and post requests:

1) get displayed (but information about the address bar can accommodate a limited, 4-5KB, if there is a large request for data files, pictures and other address bar will not accommodate data error in the address bar)

post does not display the contents of the input

 

Unified request code request

If the request is garbled to solve:

1) get way

1. Uniform each variable encoding (not recommended)

new String (the old code, the new code);

name=new String(name.getBytes("ios-8859-1"),"utf-8");

2. Modify the server.xml, a one-time change the default Tomcat submission of coding ( "utf-8")

tomcat8 and later default to "utf-8"

2) post way

A direct increase request.setCharacterEncoding ( "utf-8");

 

Guess you like

Origin www.cnblogs.com/zuiaimiusi/p/11469889.html