JSP新闻系统之六 后台登陆页面
【摘要】
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><% String path = request.getContextPath(); String basePath = request.getScheme() + "://" +...
-
<%@ 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>
文章来源: aaaedu.blog.csdn.net,作者:tea_year,版权归原作者所有,如需转载,请联系作者。
原文链接:aaaedu.blog.csdn.net/article/details/53053061
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)