JSP实现简单的用户登录并显示出用户信息的方法
时间:2020-10-29 14:23:07|栏目:JSP代码|点击: 次
本文实例讲述了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>
<%
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>
<%
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程序设计有所帮助。
上一篇:使用maven+eclipse搭建struts2开发环境
栏 目:JSP代码
下一篇:JSP连接Access数据库
本文地址:http://www.codeinn.net/misctech/17097.html