日期:2014-05-17 浏览次数:20895 次
<%@ page language="java" contentType="text/html;charset=GBK"%> <%@taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>登陆页面</title> </head> <body> <s:action name="tag1" executeResult="true"/> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Struts Blank</display-name> <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>
<?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.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="lee" namespace="/" extends="struts-default"> <action name="tag1" class="lee.TagAction"> <result name="done">welcome.jsp</result> </action> <action name="tag2" class="lee.TagAction" method=“login”> <result name="done">error.jsp</result> </action> </package> </struts>
package lee; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class TagAction extends ActionSupport{ private String author; public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String execute() throws Exception { return "done"; } public String login() throws Exception { ServletActionContext.getRequest().setAttribute("author", getAuthor()); return "done"; } }