Well, I know that there are 20 posts with the same problem here, but none of them seem to help me, so this will probably be a duplicate, but I went to all the other posts, and none of them solved mine the problem, so there must be something that I am doing wrong, or I am not making the right changes from the answers of the previous questions.
I'm trying to make a small application using Spring, and I'm still experimenting with it, but I spent 4 days trying to figure out what happened, and I just can't. I am still getting HTTP 404 status when I try to return jsp from the controller. Nothing but 404 status through Tomcat, nothing more ...
WebAppController:
@Controller public class WebAppController { @RequestMapping(value="/login", method = RequestMethod.GET) public String login() { System.out.println("You have entered the login maprequest"); return "test1"; } }
web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Hotel Application</display-name> <servlet> <servlet-name>WebApp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>WebApp</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </web-app>
webApp.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:component-scan base-package="com.iquestgroup" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
This configuration works in a simple maven project with just the one mentioned above. The problem is that the same does not work in a maven project with 3 modules (persistence, service and webapp). I copied the same thing in webapp, and when I launched it on the server, I got the status of 404 http ... although the modules were successfully built.
LE The first part of the accepted answer relates to a common servlet mapping error made by those starting with Spring. My problem was not related to this, and I ended up deleting it after the initial answer. In order not to confuse readers, the first part of the accepted answer relates to the following code:
<servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>