为什么我不能使用jsp:include来传递Spring MVC中的参数?

时间:2017-06-14 01:18:43

标签: java spring jsp spring-mvc

在我的Spring MVC项目中,在我的页面中,我想加载另一个页面。所以我使用jsp:include。但我发现我总是在另一个页面中获取null参数值。我尝试创建一个Servlet项目,我可以 很好地获得价值。我的代码出了什么问题?

这是我的第一页:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<title></title> 
<jsp:include page="../common/common.jsp" flush="true">
  <jsp:param name="gisType" value="baidu" />
 </jsp:include> 
</head> 
<body>

    

这是另一页:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% 
 String gisType = "baidu";
  gisType = request.getParameter("gisType");
  System.out.print(gisType);
 %>
  <script type="text/javascript"> 
 var map;
 var gisType = "<%=gisType%>"; 
 alert(gisType);
 </script>

我的mvc配置文件是这样的:

    <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:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-4.0.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-4.0.xsd  
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
      http://www.springframework.org/schema/task
      http://www.springframework.org/schema/task/spring-task-4.0.xsd"
>  
<context:annotation-config /> 
<aop:aspectj-autoproxy />

<context:component-scan base-package="cn.com.project.**">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 
</context:component-scan>

<mvc:annotation-driven /> 
<task:annotation-driven />
<mvc:default-servlet-handler/> 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
p:prefix="" p:suffix=".jsp" />  
<bean id="annotationMethodHandlerAdapter"
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list> 
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
        </list>
    </property>
</bean>

1 个答案:

答案 0 :(得分:0)

尝试使用$ {}表达式来获取参数,

<script type="text/javascript"> 
  var map;
  var gisType = "${param.gisType}"; 
  alert(gisType);
</script>