简体   繁体   English

Spring MVC - 当我点击jsp上的Submit按钮(发布请求)时,我的URL发生了变化,我的工作流程没有进入控制器类

[英]Spring MVC - When I am click on Submit button on jsp (Post request) my URL changed and my work flow not coming into controller class

When I am click on Submit button on jsp (Post request) my URL changed and my work flow not coming into controller class 当我点击jsp(发布请求)上的提交按钮时,我的URL发生了变化,我的工作流程没有进入控制器类

First time when I hit URL http://localhost:9080/LaunchingGateway_Maintance/services/Test my jsp will be opend but when I click on Vendor button on jsp URL will changed to http://localhost:9080/validate and my flow not comming to my controller and on browser I got The webpage cannot be found 我第一次点击URL http:// localhost:9080 / LaunchingGateway_Maintance / services / Test我的jsp将被打开,但是当我点击jsp上的Vendor按钮时,URL将更改为http:// localhost:9080 / validate并且我的流程没有来到我的控制器和浏览器我得到了无法找到的网页

please help me I am stuck here from last two week. 请帮助我,我在最后两周被困在这里。

my Controller class is : - 我的Controller类是: -

package com.us.launchingGatewayController;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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.servlet.ModelAndView;

import com.us.bean.SSOConfigDynaFldsSrveLstBean;
import com.us.validator.SSOconfigValidator;

@Controller
public class LaunchingGatewayController {


    @Autowired
    SSOConfigDynaFldsSrveLstBean SSOConfigDynaFldsSrveLstBean;

    @Autowired
    ModelAndView modelNView;

    @Autowired
    SSOconfigValidator SSOConfigValidator;


    @RequestMapping(value = "/Test", method = RequestMethod.GET)
    public ModelAndView test(HttpServletRequest httpRequest, HttpServletResponse resp)throws Exception {
        System.out.println("Test In test");
        modelNView.setViewName("test");

        return modelNView;
    }

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello(){
        System.out.println("hi");
        return "test";
    }


    @RequestMapping(value = "/validate", method = RequestMethod.POST)
    public ModelAndView validate(HttpServletRequest httpRequest, HttpServletResponse resp) throws Exception{

        System.out.println("Test In Validate");
        SSOConfigValidator.validateSSOconfig(SSOConfigDynaFldsSrveLstBean);
        modelNView.setViewName("test");
        return modelNView;


    }


}



my jsp is :-

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<html>
<head>
<title>Launching Gateway Maintenance</title>

<script language="JavaScript" type="text/javascript">   
</script>
</head>
<body bgcolor='#E8E8E8'>

    <h1 align="center">Launching Gateway Maintenance</h1>

    <form  method="POST" action="/validate">
        <center>



            <input type="submit" name="validate" value="Vendor" /> 

        </center>



    </form>


</body>
</html>




my web.xml is :-

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">    
    <display-name>LaunchingGateway_Maintance</display-name>
    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
            <servlet-name>spring-dispatcher</servlet-name>  
              <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

</web-app>


my spring-dispatcher-servlet.xml is :-

<?xml version="1.0" encoding="UTF-8"?>
<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"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
                            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">


    <context:component-scan base-package="com.us.launchingGatewayController" />
    <bean id="ssoConfigValidator" class="com.us.validator.SSOconfigValidator"></bean>

    <bean id="modelNView" class="org.springframework.web.servlet.ModelAndView"></bean>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="../jsp/" /> 
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

Something wrong with you context path. 你的上下文路径有问题。 According to form you submitting, try this: 根据您提交的表单,试试这个:

<FORM ACTION="${pageContext.request.contextPath}/validate">

Compare this two urls : 比较这两个网址:

http://localhost:9080/LaunchingGateway_Maintance/services/Test

and

http://localhost:9080/validate

So looks like you are missing some context path LaunchingGateway_Maintance 所以看起来你错过了一些上下文路径LaunchingGateway_Maintance

Check this post as well 也请查看这篇文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MVC JSP Jquery jQuery调用控制器方法单击按钮后发布重定向错误 - Spring MVC JSP Jquery call controller method on button click post redirect error 为什么在访问我的 Spring MVC 应用程序 URL 时出现 404 错误? - Why am I getting a 404 error when accessing my Spring MVC app URL? 单击提交时不会切换到另一个.jsp。 春季MVC - Doesn't switch to another .jsp when I click submit. Spring mvc JSP表单与列表提交到Spring MVC控制器 - Jsp form submit with list to spring MVC controller 当我提交表单时,Spring仅在启动时注入我的类,我的变量为null为什么? - Spring inject my class only on my startup when I submit my form my variable is null why? 当我在spring MVC中向控制器发送请求时,为什么我变为null? - Why I am getting null when I send a request to the controller in spring MVC? 使用POST请求时,Spring MVC在控制器中找不到方法 - Spring MVC cannot find method in controller when using POST request 我如何将字符串从spring控制器传递到我的jsp - how can i pass the string from spring controller to my jsp 当我提交注册表格时,它不会执行发布控制器 - When I submit my registration form it doesn't execute the post controller 我正在尝试使用Spring MVC构建应用程序,但无法弄清楚为什么HTTP请求没有到达我的Spring Controller - I am trying to build an application using Spring MVC and can't figure out why the HTTP Requests are not reaching my Spring Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM