Why index page is giving 404 error in Struts 2

If I am not including web.xml file then index file is opening properly but result page HelloWorld.jsp is giving 404 error, and when including web.xml index page is giving 404 error.

I have index.jsp file. localhost:8080 is working correctly but after that it is giving error.

See here:


Answers


In the first case the index file is opened by the default servlet, that is available on the server.

In the second case you use FilterDispatcher that is deprecated.

You should upgrade Struts to the latest version and use

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 

See how to write web application descriptor web.xml.

Simple Example

Configuring web.xml for the framework is a matter of adding a filter and filter-mapping.

FilterDispatcher Example (web.xml):

<web-app id="WebApp_9" 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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

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

Need Your Help

How to get the URL of a Tumblr photoset iframe

iframe tumblr

I am customizing my tumblr template and I need to access the URL of the iframe that contains my photoset. When I look at the html of my tumbler page, I see: