Spring MVC Controller funktioniert, erstellt jedoch nicht die angegebene Antwort-URL. Die URL wird aus der Anforderungszuordnungszeichenfolge erstellt.

Ich studiere Spring MVC-basierte Webapps. Also habe ich ein Projekt in spring mvc erstellt und mich für eclipse IDE.Apache tomcat 8 Server und jre1.8 entschieden. Die Version von spring package ist 4.2.5. In meinem Projekt habe ich die Anmeldung erstellt und diese funktionierte nach der Anmeldung einwandfrei. Ich habe die Seite an eine andere JSP namens 'branchinsert.jsp' weitergeleitet, die sich in einem anderen Ordner befindet (login.jsp und branchinsert.jsp stammen aus verschiedenen Ordnern). In Branchinsert.jsp funktioniert Spring MVC Controller, erstellt jedoch nicht die angegebene Antwort-URL. Die URL wird aus der Anforderungszuordnungszeichenfolge erstell

@RequestMapping(value="/branchsubmitinsert.travel", method=RequestMethod.POST)
public ModelAndView submitBranchInsert(@ModelAttribute BranchModel branchModel){

    ModelAndView modelAndView = new ModelAndView("/branch/branchinsert");

    return modelAndView;

}

showing 404 Fehler für die URL /ProjectName/modules/branch/branchsubmitinsert.js

Eigentlich ist die erwartete URL /branch/branchinsert.jsp (das passiert normalerweise), aber hier wurde die URL /branch/branchsubmitinsert.jsp erstellt. Warum???

dies ist mein Code

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>

ormularfeld von @ 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>

Die Controller-Klasse 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;

}

}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage