Ajax没有重定向到tile视图

时间:2013-10-10 09:03:35

标签: jquery spring-mvc tiles

您好我在手动点击网址时使用spring 3 mvc和图块,或者在onclick时返回新图块视图。但是通过ajax它会击中控制器,但不会进入视图。

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

http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <mvc:annotation-driven />
    <context:annotation-config />
    <context:component-scan base-package="in.ac.nitk.tas" />



    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>

    <bean id="ajaxViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
         <property name="viewClass" value="org.springframework.js.ajax.tiles2.AjaxTilesView"/>
    </bean>

    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>
    <bean id="jacksonMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="jacksonMessageConverter" />
            </list>
        </property>
    </bean>

</beans>

我的控制器是

@Controller
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;


    @RequestMapping("/login")
    public String login(@RequestBody final UserVO userVO, final ModelMap map,
            HttpSession session, HttpServletRequest req) {
               -
               -
               -
               -
               -


        return "adminView";
    }
}

js函数调用此

function submitLoginForm(){

    var userName =$("#userName").val();
    var password= $("#password").val();
    var userVO ={ userName: userName,
                password: password,

               };

    $.ajax({
        url : "home/login.do",
        type : "POST",
        //dataType: "html",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(userVO),
        cache: false,    //This will force requested pages not to be cached by the browser  

//        processData:false, 
        success : function(data) {
          // alert(data);
        }
    });
}

我的tiles.xml是

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

 <definition name="baseLayout" template="/WEB-INF/jsp/layout/layout.jsp">
  <put-attribute name="header" value="/WEB-INF/jsp/layout/header.jsp" />
  <put-attribute name="login" value="" />
  <put-attribute name="navigation" value="/WEB-INF/jsp/layout/navigation.jsp" />
  <put-attribute name="body" value="" />
  <put-attribute name="footer" value="/WEB-INF/jsp/layout/footer.jsp" />
 </definition>

 <definition name="login" extends="baseLayout"> 
  <put-attribute name="login" value="/WEB-INF/jsp/layout/login.jsp" />
  <put-attribute name="body" value="/WEB-INF/jsp/layout/body.jsp" />

 </definition>

 <definition name="adminView" extends="baseLayout">
  <put-attribute name="login" value="/WEB-INF/jsp/welcome.jsp" />
  <put-attribute name="body" value="/WEB-INF/jsp/admin/adminHome.jsp" />
  <put-attribute name="navigation" value="/WEB-INF/jsp/admin/adminMenu.jsp" />
 </definition>

</tiles-definitions>

0 个答案:

没有答案