re: Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解實(shí)例詳解(四)
2011-04-22 17:52 |
請問在embedded tomcat5/6中使用struts2 convention要注意什么?我在embedded tomcat5/6使用struts2 convention老是報(bào)錯(cuò):
問題代碼如下:
1.web.xml:
<web-app>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.struts.xml:
<struts>
<constant name="struts.convention.result.path" value="/WEB-INF/jsp/" />
</struts>
3.HelloAction.java:
package com.synertone.ssh.paging.action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport {
private String message;
public String getMessage() {
return message;
}
@Override
public String execute() {
message = "lady gaga!";
return SUCCESS;
}
}
4.hello.jsp:
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<body>
The message is: ${message}
</body>
</html>
5.tomcat啟動(dòng)類startup.java:
Tomcat tomcat = new Tomcat();
String projectPath = new File("").getAbsolutePath();
tomcat.setBaseDir(projectPath);
tomcat.setPort(8080);
try {
tomcat.addWebapp("", projectPath + "/webapps/SSH");
} catch (ServletException e) {
e.printStackTrace();
throw e;
}
try {
tomcat.start();
} catch (LifecycleException e) {
e.printStackTrace();
throw e;
}
輸入
http://localhost:8080/index.jsp,能訪問index.jsp頁面。輸入
http://localhost:8080/hello或hello.action則報(bào)錯(cuò):
There is no Action mapped for namespace / and action name hello. - [unknown location]
同樣的代碼部署在非embeded tomcat中卻能訪問成功。
這是為什么呢?望大象指點(diǎn)一下,感激不盡!
回復(fù) 更多評論