1

方法我想重定向到家

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

家庭控制器

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

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>

根上下文.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>

运行访问 url 后到家的 url 是:

本地主机:8080/proyecto/acceder

在控制台或日志中没有显示任何错误,到达家中但没有更改 url 有没有人想到会发生什么?

4

2 回答 2

2

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

于 2013-10-11T12:36:42.540 回答
0

You are using a GET method (using the url directly), but your controller is using POST. Try using GET instead of Post,

@RequestMapping(value = "/acceder", method = RequestMethod.GET)
于 2013-09-16T12:26:58.323 回答