Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSP<;形式动作=";邮政「&燃气轮机;不重定向到控制器,Spring MVC_Spring_Spring Boot_Spring Mvc_Jsp - Fatal编程技术网

JSP<;形式动作=";邮政「&燃气轮机;不重定向到控制器,Spring MVC

JSP<;形式动作=";邮政「&燃气轮机;不重定向到控制器,Spring MVC,spring,spring-boot,spring-mvc,jsp,Spring,Spring Boot,Spring Mvc,Jsp,我刚刚开始使用SpringMVC开发SpringBootWeb应用程序。在我的POC中,我试图显示上一页上选择的值 登录屏幕工作正常。单击具有有效凭据的登录按钮后,它将按预期重定向到success.jsp。现在,当我单击success.jsp中的提交按钮时,它将调用控制器方法[action1()/action2()],并在控制台中打印消息 控制器类: @RequestMapping(value = "login", method = RequestMethod.GET) public S

我刚刚开始使用SpringMVC开发SpringBootWeb应用程序。在我的POC中,我试图显示上一页上选择的值

登录屏幕工作正常。单击具有有效凭据的登录按钮后,它将按预期重定向到success.jsp。现在,当我单击success.jsp中的提交按钮时,它将调用控制器方法[action1()/action2()],并在控制台中打印消息

控制器类:

@RequestMapping(value = "login", method = RequestMethod.GET)
    public String init(Model model) {
        model.addAttribute("msg", "Please Enter Your Login Details");
        System.out.println("INIT ====");
        return "login.jsp";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String submit(Model model,
            @ModelAttribute("loginBean") LoginBean loginBean) {
        System.out.println("submit22 ====");
        if (loginBean != null && loginBean.getUserName() != null
                & loginBean.getPassword() != null) {
            if (loginBean.getUserName().equals("a")
                    && loginBean.getPassword().equals("a")) {
                model.addAttribute("msg", loginBean.getUserName());
                return "success.jsp";
            } else {
                model.addAttribute("error", "Invalid Details");
                return "login.jsp";
            }
        } else {
            model.addAttribute("error", "Please enter Details");
            return "login.jsp";
        }
    }

    @RequestMapping(value="/addDetails",params="submit",method=RequestMethod.GET)
    public void action1()
    {
        System.out.println("submit block called GET ");
    }

    @RequestMapping(value="/addDetails",params="submit",method=RequestMethod.POST)
    public void action2()
    {
        System.out.println("submit block called POST");
    }
login.jsp

<form:form name="submitForm" method="POST">

    <div align="center">
        <table>
            <tr>
                <td>User Name</td>
                <td><input type="text" name="userName" /></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="password" name="password" /></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Submit" /></td>
            </tr>
        </table>
        <div style="color: red">${error}</div>

    </div>
</form:form>

用户名
密码
${error}
success.jsp

<form:form action="/addDetails" method="post">
     <table>
      <tr>
      <td><form:label path = "name">Name : </form:label></td>
        <td>
             <input type="text" name="name">
        </td>
      </tr>
      <tr>
           <td><form:label path = "gender">Gender : </form:label></td>
           <td>
              <input type="radio" name="gender" value="male" > Male 
              <input type="radio" name="gender" value="female"> Female
              <input type="radio" name="gender" value="other"> Other
           </td>
        </tr>         
      <tr>
      <td>
              <input type = "submit" value = "Submit" name ="submit"/>
       </td>
       </tr>       
     </table>
</form:form>

姓名:
性别:
男性
女性
其他
web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<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" id="WebApp_ID" version="2.5">
  <display-name>SampleWebApp</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/application-config.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/mvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

SampleWebApp
上下文配置位置
类路径:spring/application-config.xml
org.springframework.web.context.ContextLoaderListener
调度员服务
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/mvc-config.xml
1.
调度员服务
/
mvc-config.xml:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
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    
http://www.springframework.org/schema/mvc   
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <mvc:annotation-driven/>
    <context:component-scan base-package="org.dm.springboot"></context:component-scan>
<bean
  class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
            <property name="prefix" value="/WEB-INF/view/"/>
            <property name="suffix" value=".jsp"/>
    </bean>
</beans>


那么运行时出现了什么错误?请澄清控制台中没有错误。它只是没有重定向。您还可以告诉我应用程序名是否默认设置为上下文路径吗?或者必须在某个地方进行配置?如果没有配置,是否有问题?