struts2 标签登陆例子(简单)
2013-11-30 21:36
351 查看
文件目录:
文件内容:
ZLoginAction.java
package com.zxl.action;
import com.opensymphony.xwork2.ActionSupport;
public class ZLoginAction extends ActionSupport {
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private String username;
private String password;
public String execute() throws Exception {
if(username.equals("a")&&password.equals("b")){
return SUCCESS;
}else {
return INPUT;
}
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Struts3</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
welcome
</body>
</html>
文件内容:
ZLoginAction.java
package com.zxl.action;
import com.opensymphony.xwork2.ActionSupport;
public class ZLoginAction extends ActionSupport {
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private String username;
private String password;
public String execute() throws Exception {
if(username.equals("a")&&password.equals("b")){
return SUCCESS;
}else {
return INPUT;
}
}
}
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> <!-- 改变url现实的后缀,默认是action --> <constant name="struts.action.extension" value="xhtml" /> <package name="struts2login" extends="struts-default"> <!-- 这里的Class是由Spring里面制定的ID,如果单独用struts2,则这里是包名+类名 --> <action name="LoginAction" class="com.zxl.action.ZLoginAction"> <result name="success" >/welcome.jsp</result> <result name="input">/Login.jsp</result> </action> </package> </struts>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Struts3</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="/struts-tags" prefix="s" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <s:form action="LoginAction" method="post"> <s:label value="login"></s:label> <s:textfield name="username" label="username"></s:textfield> <s:password name="password" label="password"></s:password> <s:submit value="ok" ></s:submit> </s:form> </body> </html>welcome.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
welcome
</body>
</html>
相关文章推荐
- struts2入门-第一个例子==》第一个struts2实例——HelloWorld==》Struts2.0搭建和简单实例==>写一个Steuts2的经典入门案例,做了一个登陆程序作为入门例子
- struts2链接数据库的简单登陆验证
- Struts2中UI常用标签及其简单配置
- struts2简单入门-登陆示例
- Struts2之如何使用简单的UI标签
- 【破浪学习】asp.net简单的注册或者登陆三层架构的例子
- 整合Struts2,Hibernate和Spring的一个简单例子
- Java Web学习笔记(2)——一个简单的Struts2例子
- Ognl标签常用例子 只能在Struts2中使用
- extJs+json实现的一个登陆验证的简单例子
- 用struts2标签简单,解决字符长度超出文本框问题,
- Ajax.net+模态窗口的登陆简单例子
- struts2——简单登陆实例
- 第一个简单的Struts2的例子
- struts2原理,标签及干净Struts2小例子
- Java Web : Struts2第一个简单例子 浅解
- Struts2上传与下载文件 简单例子
- struts2简单入门-登陆示例
- struts2基础——最简单的一个例子
- struts2 搭建框架例子如登陆界面,要求是用最新版struts2。