JSP implements a simple user login and displays user information

  • 2021-06-29 11:44:25
  • OfStack

This article provides an example of how JSP implements a simple user login and displays user information.Share it for your reference.The implementation is as follows:

login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>  
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
  </head> 
   
  <body> 
  <form action="login_success.jsp" method = "post"> 
   User name: <input type ="text" name = "username"/><br> 
   Password: <input type = "password" name ="password"><br> 
   <input type ="submit" value=" Submit "/>  
   </form> 
  </body> 
</html>

login_success.jsp is used to display user information

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>  
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
  </head> 
   
  <body> 
  <% 
  String uname = request.getParameter("username"); 
  String pwd = request.getParameter("password"); 
  out.println(uname); 
  out.println(pwd); 
   %> 
  </body> 
</html>

I hope that the description in this paper will be helpful to everyone's jsp program design.


Related articles: