1 隨著struts2的改版,現在改的越來越亂了,用了很多自己的東西,要匯入的包越來越多了,截下圖吧,感覺越來越不好用了,這9個缺一不可
2 主配置
<?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"> <filter><filter-name>struts2</filter-name><!-- <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>--><!-- --><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter><!-- FilterDispatcher用來初始化struts2並且處理所有的WEB請求。 --><filter-mapping><filter-name>struts2</filter-name> <url-pattern>/*</url-pattern><!-- <url-pattern>*.action</url-pattern> --></filter-mapping> <display-name>ss2</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></web-app>
這裡面有 原先的配置和後來的,新的jia肯定不再適合原來的主類了
3 src下建立struts.xml
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><package name="main" extends="struts-default" ><action name="mainAction" class="com.YCHZ.jquery.action.LoginAction"method="execute"><result name="success">/success.jsp</result><result name="error">/error.jsp</result></action></package></struts>
4 建立action
package com.YCHZ.jquery.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{public String execute(){System.out.println("ok");return SUCCESS;}}