zoukankan      html  css  js  c++  java
  • 登录页面

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    	<h3>登录页面</h3>
    	
    	<form action="/day3/login" method="POST">
    		账号: <input type="text" name="username"/><br/>
    		密码: <input type="text" name="password"/><br/>
    		<input type="submit" value="朕要登录"/>
    	</form>
    </body>
    </html>
    

      

    解决了中文乱码问题

    package per.mjn._06_encoding;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    // 接收和处理登陆的信息
    @WebServlet("/login")
    public class LoginServlet extends HttpServlet{
    
    	private static final long serialVersionUID = 1L;
    
    	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //		System.out.println("LoginServlet.service()");
    		// 对于POST请求, 可以设置请求的编码
    		req.setCharacterEncoding("UTF-8");
    		String username = req.getParameter("username");
    		
    //		// 1. 按照ISO-8859-1把乱码恢复成二进制形式
    //		byte[] data = username.getBytes("ISO-8859-1");
    //		// 2. 再把二进制形式的数据使用UTF-8重新编码
    //		username = new String(data, "UTF-8");
    		
    		String password = req.getParameter("password");
    		System.out.println(username + ", " + password);
    	}
    }
    

      

  • 相关阅读:
    Redis命令行之Hash
    Redis命令行之String
    Redis配置
    访问者模式【行为模式】
    状态模式【行为模式】
    责任链模式【行为模式】
    观察者模式【行为模式】
    策略模式【行为模式】
    模板方法模式【行为模式】
    组合模式【结构模式】
  • 原文地址:https://www.cnblogs.com/mjn1/p/11469751.html
Copyright © 2011-2022 走看看