views:

295

answers:

1

I have a simple spring 3 mvc application, that just ouputs index.aspx when someone browses to http://localhost:8080/

When I do RunAs and run on server option (which is hooked into tomcat 6), it opens up the browser to http://localhost:8080/springmvc2/ (where springmvc2 is the applications name).

I have build this same simple test app using netbeans at it works fine using the url http://localhost:8080/

My web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Springmvc2</display-name>
    <description>Springmvc2 web application</description>

    <servlet>
        <servlet-name>Springmvc2</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Maps all /app requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>Springmvc2</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

And my HomeController is:

package com.springmvc2.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;



@Controller
public class HomeController {


    @RequestMapping("/")
    public String Index(){

        return "index";
    }


    @RequestMapping("/test")
    public String Index2(){

        return "index";
    }


}

You can view my pom.xml file here: http://stackoverflow.com/questions/2234059/using-eclipse-with-maven-plugin-how-should-i-setup-my-build-so-it-deploys-to-tom

This is the target folder that is generated also:

/target
/target/springmvc2/meta-inf
/target/springmvc2/web-inf
/target/springmvc2/test.html
/target/war/springmvc2.war
/target/pom.xml

I created test.html just to see if at least this renders, but http://localhost:8080/test.html doesn't work, and http://localhost:8080/springvc2/test.html doesn't work either.

I am getting a 404 error so I guess it is not deploying to tomcat properly, especially since the test.html file doesn't even render.

But maybe the test.html isn't rendering because I have this in my springmvc2-servlet.xml:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
            p:suffix=".jsp" p:order="2"/>

I have to admit, Java development is riddled with configuration issues, especially for newbies!!

Update

compiling and doing a runas serving, opens the browser and I get this message from tomcat:

WARNING: No mapping found for HTTP request with URI [/springmvc2/] in DispatcherServlet with name 'springmvc2'
+1  A: 

The URL should be http://localhost:8080/springmvc2/test.html (the m is missing in the one you pasted).

Update: Try <url-pattern>/*</url-pattern> instead of <url-pattern>/</url-pattern>

Pascal Thivent
but why was http://localhost:8080/ working when I was testing things out in netbeans?
Blankman
@Blankman Because the webapp is deployed under the root context `/` in NetBeans while it's deployed under `/springmvc2` under Eclipse.
Pascal Thivent
how can I change that? (thanks a bundle!)
Blankman
@Blankman In the server view, **double-click** on the Tomcat server, select the **Modules** tab and **Edit** the **Web Module** to change the **Path**.
Pascal Thivent
Ok I did that, still doesn't work but at least I fixed that setting thanks!
Blankman