本文執行個體講述了JSP實現簡單的使用者登入並顯示出使用者資訊的方法。分享給大家供大家參考。具體實現方法如下:
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">
使用者名稱:<input type ="text" name = "username"/><br>
密碼:<input type = "password" name ="password"><br>
<input type ="submit" value="提交"/>
</form>
</body>
</html>
login_success.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>
<%
String uname = request.getParameter("username");
String pwd = request.getParameter("password");
out.println(uname);
out.println(pwd);
%>
</body>
</html>
希望本文所述對大家的jsp程式設計有所協助。