简体   繁体   中英

Why I can not use jsp:include to pass a parameter in Spring MVC?

In my Spring MVC project,In my page,I want to load the other page.So I use jsp:include .But I find the I always get the null parameter value in the other page.I try to create a single Servlet project,And I can get the value well. What's wrong with my code?

This is my first page:

<%@ 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>

This is the other page:

<%@ 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>

My mvc config file is like this:

    <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>

Try to use ${} expression to get the param,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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