SpringMVC Controller 传MAP值到JSP页面,取不到值,在线等待
张沛洁 2018-04-17 04:36:19 spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd" >
<!-- <import resource="classpath*:Spring-RabbitMQ.xml" /> -->
<context:component-scan base-package="com.cict.controller" />
<!-- 激活annotation功能 -->
<context:annotation-config />
<mvc:annotation-driven/>
<!-- 激活annotation功能 -->
<!-- <context:spring-configured /> -->
<bean id="InternalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
Controller.java
@RequestMapping(value = "Hello.do",method=RequestMethod.POST)
public String SendMessage(@RequestParam(value = "txtDisplay") String disPlay
,HttpServletRequest request) throws Exception {
Map<String, String> map = new HashMap<String, String>();
logger.info(disPlay);
logger.info(request.getMethod());
logger.info(request.getParameter("txtDisplay"));
String ip = null;
InetAddress iaAddress = null;
iaAddress = InetAddress.getLocalHost();
ip = iaAddress.getHostAddress();
logger.info(ip);
map.put("name", disPlay);
map.put("ip", ip);
return "Hello";
}
Hello.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%-- <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<%-- Hello ${map.name },your ip is ${map.ip } --%>
${name},${ip}
</body>
</html>