幾年前學習了一陣子Struts2,也開發了些小項目,后來工作變動,幾年沒動技術,這兩天又想撿起來,發現一些配置有了變化,重新學習,記錄些內容,供自己查詢。
環境沒敢用最新的,MyEclipse用的是8.5的版本,Tomcat最終選擇了6,JDK也是用的7,Struts2的版本2.3.16.3。通常的配置沒什么要記錄的,主要記錄下出問題的地方:
1、Tomcat
從MyEclipse啟動Tomcat一直報錯,后來下載了一個tcnative-1.dll文件才解決,版本要求比較嚴格,對于Tomcat6.0.41而言,這個動態鏈接庫版本要求是1.1.30,1.1.3都不行,不知道有什么區別,將文件拷貝到jre/bin下即可。
2、web.xml文件內容
1 <?xml version="1.0" encoding="UTF-8"?>
2 <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">
3
4 <display-name>Struts Test</display-name>
5
6 <filter>
7 <filter-name>struts2</filter-name>
8 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
9 </filter>
10
11 <filter-mapping>
12 <filter-name>struts2</filter-name>
13 <url-pattern>/*</url-pattern>
14 </filter-mapping>
15
16 <welcome-file-list>
17 <welcome-file>index.html</welcome-file>
18 </welcome-file-list>
19
20 </web-app>
21
3、struts.xml文件內容
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE struts PUBLIC
3 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
4 "http://struts.apache.org/dtds/struts-2.3.dtd">
5
6 <struts>
7
8 <constant name="struts.enable.DynamicMethodInvocation" value="true" />
9 <constant name="struts.devMode" value="true" />
10
11 <package name="default" namespace="/" extends="struts-default">
12
13 <default-action-ref name="index" />
14
15 <global-results>
16 <result name="error">/error.jsp</result>
17 </global-results>
18
19 <global-exception-mappings>
20 <exception-mapping exception="java.lang.Exception" result="error"/>
21 </global-exception-mappings>
22
23 <action name="action名" class="java包名及類名">
24 <result name="success">/調用的jsp頁面文件p</result>
25 </action>
26 </package>
27
28 <include file="example.xml"/>
29
30 <!-- Add packages here -->
31
32 </struts>
33
4、調用時發現action名定義了大小寫后,地址欄也要輸入相應的大小寫,否則報錯。這個問題困擾了好久。。。。。
By SeeSea