■
sampleプロジェクト ・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/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="struts_blank" version="2.4"> <display-name>Struts Blank Convention</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> ・libの中身(\struts-2.5.2\lib) aopalliance-1.0.jar asm-3.3.jar asm-commons-3.3.jar asm-tree-3.3.jar commons-fileupload-1.3.2.jar commons-io-2.4.jar commons-lang3-3.4.jar commons-logging-1.1.3.jar freemarker-2.3.23.jar javassist-3.20.0-GA.jar log4j-api-2.5.jar ognl-3.1.10.jar spring-aop-4.1.6.RELEASE.jar spring-beans-4.1.6.RELEASE.jar spring-context-4.1.6.RELEASE.jar spring-core-4.1.6.RELEASE.jar spring-expression-4.1.6.RELEASE.jar struts2-config-browser-plugin-2.5.2.jar struts2-convention-plugin-2.5.2.jar struts2-core-2.5.2.jar ・hello.jsp <%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title><s:text name="hello.message"/></title> </head> <body> <h2><s:property value="message"/></h2> </body> </html> ・struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.devMode" value="false"/> </struts> ・Index.java package local.sample.actions; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; @Results({ @Result(name = Action.SUCCESS, location = "${redirectName}", type = "redirectAction") }) public class Index extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private String redirectName; public String execute() { redirectName = "hello"; return Action.SUCCESS; } public String getRedirectName() { return redirectName; } } ・HelloAction.java package local.sample.actions; import com.opensymphony.xwork2.ActionSupport; /** * <code>Set welcome message.</code> */ public class HelloAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; private static int count = 0; public String execute() throws Exception { setMessage(String.valueOf(count++)); return SUCCESS; } /** * Provide default valuie for Message property. */ public static final String MESSAGE = "hello.message"; /** * Field for Message property. */ private String message; /** * Return Message property. * * @return Message property */ public String getMessage() { return message; } /** * Set Message property. * * @param message Text to display on HelloWorld page. */ public void setMessage(String message) { this.message = message; } } http://localhost:8080/sample/config-browser/showConfig.action