[英]Spring MVC & JSP: How to pass a parameter from the controller to JSP?
[英]Why I can not use jsp:include to pass a parameter in 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.