re: Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解(四)
2011-04-22 17:52 |
请问在embedded tomcat5/6中使用struts2 convention要注意什么?我在embedded tomcat5/6使用struts2 convention老是报错:
问题代码如下:
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启动类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则报错:
There is no Action mapped for namespace / and action name hello. - [unknown location]
同样的代码部署在非embeded tomcat中却能访问成功。
这是为什么呢?望大象指点一下,感激不尽!
回复 更多评论