2
votes

I'm trying to run an application in Tomcat. I create an application that generates a war file that I put on the Tomcat to run the application but when I try to run

http://localhost:8080/AppletTest/

it gives me error:

HTTP Status 404 -

type Status report

message

description The requested resource is not available.

Apache Tomcat/8.0.28

And more detailed:

06-Nov-2015 16:35:07.052 WARNING [http-nio-8080-exec-51] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/AppletTest/] in DispatcherServlet with name 'mvc-dispatcher'

In the dir installation of tomcat my app resides on

~/apache-tomcat-8.0.28/webapps/

and the index.html and the other files are on the

~/apache-tomcat-8.0.28/webapps/AppletTest/WEB-INF/pages/index.html

.

I'm making any error?

My files:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app
        version="3.0"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>Test</display-name>


    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup></load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

</web-app>

mvc-dispatcher-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.something.controller" />
    <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.html</value>
        </property>
    </bean>

</beans>
1

1 Answers

1
votes

You have created a Spring application. On your Web.xml you have mapped all requests (/*) to your Spring Servlet.

Now, you have to create a controller that will listen to your URL.

Example:

@Controller
public class IndexController {

    @RequestMapping(value = "", method=RequestMethod.GET)
    public String index(Model m)  {
        return "index/index";
    }

}

Now this method will listen the {context}/ url and will return the index.html view.