Spring MVC Controller funciona pero no crea la URL de respuesta especificada, está creando la url de la cadena de mapeo de solicitud
Estoy estudiando aplicaciones web basadas en MVC de primavera. Así que creé un proyecto en spring mvc y elegí eclipse IDE. Apache tomcat 8 server y jre1.8 la versión del paquete spring es 4.2.5. En mi proyecto, creé el inicio de sesión y funcionó bien después de iniciar sesión. Redirigí la página a otro jsp llamado 'branchinsert.jsp' que estaba en otra carpeta (login.jsp y branchinsert.jsp son de diferentes carpetas). En Branchinsert.jsp Spring MVC Controller está funcionando pero no crea la URL de respuesta especificada, está creando la url de la cadena de mapeo de solicitud que significa que si estoy dando el patrón como se menciona a continuación,
@RequestMapping(value="/branchsubmitinsert.travel", method=RequestMethod.POST)
public ModelAndView submitBranchInsert(@ModelAttribute BranchModel branchModel){
ModelAndView modelAndView = new ModelAndView("/branch/branchinsert");
return modelAndView;
}
mostrando un error 404 para la url /ProjectName/modules/branch/branchsubmitinsert.jsp
En realidad, la url que esperaba es /branch/branchinsert.jsp(esto es lo que suele suceder), pero aquí se creó /branch/branchsubmitinsert.jsp url. ¿¿¿¿por qué????
este es mi código
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_3_0.xsd" id="WebApp_ID"
version="3.0">
<display-name>CalicutTravels</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener><listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.classes.controller">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
</beans>
spring-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:annotation-config />
<context:component-scan base-package="com.classes.controller">
</context:component-scan>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/modules/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- declare beans -->
<bean id="userDaoImplementation"
class="com.classes.dao.login.UserDaoImplementation" />
<bean id="userServiceImplementation"
class="com.classes.service.login.UserServiceImplementation" />
<!-- declare datasource bean "jdbc:postgresql://hostname:port
/dbname","username", "password");-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432
/db_enterpricer_travel" />
<property name="username" value="vishnu" />
<property name="password" value="root" />
</bean>
</beans>
campo de formulario branchinsert.jsp
<form action='branchsubmitinsert.travel' id='brach_submit' method='post' >
<fieldset class="well the-fieldset">
<legend class="the-legend"> INSERT </legend>
<table>
<tr>
<th> Branch Name :</th>
<td> <input type="text" name='branchName' id='branchName' /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="button" class="btn btn-default" value='INSERT' onclick='return validateBranchInsert()'/></td>
</tr>
</table>
</fieldset>
</form>
La clase de controlador BranchController.java
package com.classes.controller.branch;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;
import com.classes.service.branch.BranchModel;
/**
* @author vishnu
*
*/
@Controller
@RequestMapping("/branch")
public class BranchController {
@RequestMapping(value="/branchinsert.travel", method=RequestMethod.GET)
public ModelAndView getBranchInsert(){
ModelAndView modelAndView = new ModelAndView("/branch/branchinsert");
return modelAndView;
}
@RequestMapping(value="/branchupdate.travel", method=RequestMethod.GET)
public ModelAndView getBranchUpdate(){
ModelAndView modelAndView = new ModelAndView("/branch/branchupdate");
return modelAndView;
}
@RequestMapping(value="/branchshow.travel", method=RequestMethod.GET)
public ModelAndView getBranchShow(){
ModelAndView modelAndView = new ModelAndView("/branch/branchshow");
return modelAndView;
}
@RequestMapping(value="/branchdelete.travel", method=RequestMethod.GET)
public ModelAndView getBranchDelete(){
ModelAndView modelAndView = new ModelAndView("/branch/branchdelete");
return modelAndView;
}
@RequestMapping(value="/branchsubmitinsert.travel",
method=RequestMethod.POST)
public ModelAndView submitBranchInsert(@ModelAttribute BranchModel
branchModel){
ModelAndView modelAndView = new ModelAndView("/branch/branchinsert");
modelAndView.addObject("branch",branchModel);
return modelAndView;
}
}