0

Have searched on the web for a while, and did not find the answer for my problem. Any insights are welcome.

I followed the instructions at https://github.com/apache/struts-examples/tree/master/helloworld, and can access the servlet at http://myhost.net:8080/hello_world/index.action.

Now I want to make the servlet under hello_world directly accessible through http://myhost.net:8080. I made changes on struts.xml as follows:

<?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>

The web.xml is as follows:

<?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>

With these change, I can access index.jsp through http://myhost.net:8080/index.jsp". However, I still cannot access it using http://myhost.net:8080" directly. The following is the error that I get:

HTTP ERROR 404
Problem accessing /. Reason:
There is no Action mapped for namespace [/] and action name [] associated with context path [].

I am using Jetty 8.1.15 as the container.

4

1 回答 1

0

您无法访问 http://myhost.net:8080,因为您没有到此 url 的操作映射。更改您的配置

<action name="">
    <result>/index.jsp</result>
</action>
于 2014-08-09T09:06:41.377 回答