简单的登录系统
一般的用session,具体自己完成。
- client端 Login.jsp
<html>
<head>
<title>字体设置</title>
</head>
<body>
<h1>演示text输入域</h1>
<hr>
<form action="Login" method="post">
登录名:<input type="text" name="user.userName" ><br>
密码:<input type="password" name="user.password" ><br>
<input type="submit" value="登录">
</form>
</body>
</html>
- web.xml 为默认,不需要改变
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
- struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="Login" namespace="/" extends="struts-default">
<action name="Login " class="com.jsly.drp.sysmgr.manager.DengluAction" >
<result name="success">main.jsp </result>
<result name="input">error.jsp</result>
</action>
</package>
<!-- Add packages here -->
</struts>
- Denglu Action.jsp
package com.jsly.drp.sysmgr.manager;
import java.lang.reflect.Field;
import com.jsly.drp.sysmgr.domain.User;
import com.opensymphony.xwork2.ActionSupport;
public class DengluAction extends ActionSupport{
private User user;
public User getUser() {
System.out.println("getUser");
return user;
}
public void setUser(User user) {
System.out.println("setUser");
this.user = user;
}
public String execute()throws Exception{
System.out.println("构造函数");
if("jsly".equals(user.getUserName())&&"123456".equals(user.getPassword())){
return SUCCESS;
}else{
return INPUT;
}
}
}
*
- 返回客户端的main.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>系统</title>
</head>
<body>
<!-- ${user.userName} -->
<s:property value="user.userName"/>欢迎您!
<s:debug></s:debug>
<a href = "userManager/userManager.jsp">用户管理</a>
</body>
</html>