为什么我不能使用 jsp:include 在 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>

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

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

最新更新