[英]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. 在我的Spring MVC项目中,在我的页面中,我想加载另一个页面。所以我使用jsp:include
。但是我发现我总是在另一个页面中获得null参数值。我尝试创建一个Servlet项目,而且我可以很好地获得价值。 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: 我的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>
Try to use ${} expression to get the param, 尝试使用$ {}表达式获取参数,
<script type="text/javascript">
var map;
var gisType = "${param.gisType}";
alert(gisType);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.