简体   繁体   English

Spring MVC 3.0后没有更改重定向URL

[英]No change redirect url after spring mvc 3.0

Method I want to redirect to the home 我想重定向到家庭的方法

@RequestMapping(value = "/acceder", method = RequestMethod.POST)
public String accederPost(Locale locale, Model model, Usuario usuario,HttpServletRequest request) {
    return "redirect:/";
}

Home Controller 家庭控制器

@RequestMapping(value = "/")
public String home(Locale locale, Model model) {        
    model.addAttribute("atributo", new Atributo());
    return "home";
}

web.xml web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
      <servlet-name>appServlet</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/spring/root-context.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
      <servlet-name>appServlet</servlet-name>
      <url-pattern>/</url-pattern>
    </servlet-mapping>   
    <welcome-file-list>
      <welcome-file>portada.jsp</welcome-file>
    </welcome-file-list>
</web-app>

root-context.xml 根的context.xml

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">  
    <context:annotation-config />  
    <context:component-scan base-package="com.baseapp.web" />      
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />        
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven />
    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>   
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>    
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
    </bean>     
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver">
    </bean>         
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="100000"/>
    </bean>     
    <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="localeChangeInterceptor" />
            </list>
        </property>
     </bean>          
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties">  
    </bean>           
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}"
        p:password="${jdbc.password}" p:maxActive="${jdbc.maxActive}" p:maxIdle="${jdbc.maxIdle}" p:maxWait="${jdbc.maxWait}" p:logAbandoned="${jdbc.logAbandoned}" 
        p:removeAbandoned="${jdbc.removeAbandoned}" p:removeAbandonedTimeout="${jdbc.removeAbandonedTimeout}">  
    </bean>       
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" p:configLocation="/WEB-INF/hibernate.cfg.xml" >  
        <property name="dataSource" ref="dataSource" />
        <property name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>            
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.minPoolSize">${jdbc.maxIdle}</prop>
                <prop key="hibernate.maxPoolSize">${jdbc.maxActive}</prop>
                <prop key="hibernate.timeout">${jdbc.removeAbandonedTimeout}</prop>
            </props>
        </property>
        <property name="mappingResources">
             <list>
                  <value>/com/responsea/web/model/hbm/A.hbm.xml</value>
              <value>/com/responsea/web/model/hbm/B.hbm.xml</value>  
             </list>
        </property>
    </bean>         
    <tx:annotation-driven transaction-manager="transactionManager" />       
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory">  
    </bean>        
 </beans>

The url that is when it comes to the home after running the access url is: 运行访问URL后进入家庭的URL是:

localhost:8080/proyecto/acceder 本地主机:8080 / PROYECTO / acceder

Shows no errors on the console or in the logs, arrives at the home but without changing the url did anyone think what might be happening? 在控制台或日志中未显示任何错误,到达了家,但没有更改url,没有人认为会发生什么吗?

解决了,使用jquery mobile激活了参数:pushStateEnabled和ajaxEnabled,并将表单提交为在同一页面上重新加载ajax内容,解决了将这些参数的值更改为false的js的问题。

You are using a GET method (using the url directly), but your controller is using POST. 您正在使用GET方法(直接使用url),但是您的控制器正在使用POST。 Try using GET instead of Post, 尝试使用GET代替Post,

@RequestMapping(value = "/acceder", method = RequestMethod.GET)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM