【发布时间】:2014-08-09 06:02:49
【问题描述】:
在网上搜索了一段时间,并没有找到我的问题的答案。欢迎任何见解。
我按照https://github.com/apache/struts-examples/tree/master/helloworld 的说明进行操作,并且可以通过http://myhost.net:8080/hello_world/index.action 访问servlet。
现在我想通过http://myhost.net:8080 直接访问hello_world 下的servlet。我对 struts.xml 做了如下修改:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<package name="basicstruts2" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="hello" class="helloworld.action.HelloWorldAction" method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Hello World Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>
通过这些更改,我可以通过 http://myhost.net:8080/index.jsp" 访问 index.jsp。但是,我仍然无法直接使用 http://myhost.net:8080" 访问它。以下是我得到的错误:
HTTP ERROR 404
Problem accessing /. Reason:
There is no Action mapped for namespace [/] and action name [] associated with context path [].
我使用 Jetty 8.1.15 作为容器。
【问题讨论】:
标签: java spring jsp struts2 action-mapping