今天嘗試搭建了struts2環境,並且編寫了第一個struts程式–HelloWorld。環境搭建很順利,主要分為3步:引入jar包,編寫struts.xml,配置web.xml。詳情可以參考:http://www.blogjava.net/lzhidj/archive/2008/07/08/213445.html
但是有一個問題困擾:tomcat可以啟動成功,但是就是“此程式無法顯示網頁”。查閱後的解決辦法:
http://www.mamicode.com/info-detail-492134.html。
主要是因為tomcat配置的server path不是tomcat的安裝路徑,而且要選擇使用tomcat installation。部署直接選取webapps。
這個問題真是困擾了幾個小時,特依此警戒。
另外,還有web.xml中
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>Struts</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:ApplicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <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>
listener 和 fliter 都要寫。老師在示範時,也沒有寫,但是就沒有問題,疑問。。