您的位置:首页 > Web前端 > JavaScript

JSP新闻系统之六 后台登陆页面

2016-11-06 09:44 288 查看
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>

<title>用户登陆</title>
<link rel="stylesheet" href="../css/css.css" type="text/css"></link>
</head>
<body  bgcolor="#31827C">
<form action="login_action.jsp" method="post">
<table width="99%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="100%" align="center" valign="middle"><p> </p>
<table width="700" height="440" border="0" align="center" cellpadding="0" cellspacing="0" background="pic/login.jpg">
<tr>
<td><table width="100%" height="354" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="121"> </td>
<td> </td>
</tr>
<tr>
<td width="62%" height="158"> </td>
<td width="38%" valign="bottom">
<table width="89%" height="99" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" height="30"><div align="right">用户名:</div></td>
<td width="70%" height="30"><label>
<input type="text" name="username" size="15" style="height:22px"/>
</label></td>
</tr>
<tr>
<td height="18"><div align="right">密 码:</div></td>
<td height="18"><label>
<input type="password" name="userpwd"  size="15" style="height:22px"/>
</label></td>
</tr>
<tr>
<td height="18"><div align="right"><input type="checkbox" name="saveMessage"/></div></td>
<td height="18"><label>
两周内自动登录
</label></td>
</tr>
<tr>
<td height="50"> </td>
<td height="50" valign="top"><input type="submit" value="提交">
<input type="reset" value="取消"></td>
</tr>
</table>

</td>
</tr>
<tr>
<td height="75"> </td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<p></p>
<p> </p></td>
</tr>
</table>
</form>
</body>
</html>
登陆action页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %>

<%
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>
<base href="<%=basePath%>">
<title>My JSP 'login_action.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>

<body>
<%
//获取页面数据
request.setCharacterEncoding("utf-8");
String username=request.getParameter("username");
String userpwd=request.getParameter("userpwd");
//调用Dao方法进行查询;
UserDao ud=new UserDaoImpl();
User user=ud.queryUserByNameAndPwd(username,userpwd);
if(user!=null){//user:是一个登陆对象
//如果登陆成功,则设置当前的session
session.setAttribute("user",user);
response.sendRedirect("welcome.jsp");//成功到欢迎页面;
}else{
session.setAttribute("msg","登陆失败,请检查用户名和密码");
response.sendRedirect("login.jsp");//失败还回登陆页面
}
%>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: