springMVC 使用jstl

1. pom.xml
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>taglibs</groupId>
			<artifactId>standard</artifactId>
			<version>1.1.2</version>
		</dependency>


2. web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="3.0">


3.xxx-servlet.xml
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="requestContextAttribute" value="rc"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp"/>
    </bean>


4. controller
@RequestMapping("/list.do")
	public ModelAndView list() {
		List<Map<String, String>> list = userService.listAll();
		ModelAndView view = new ModelAndView("list.jsp");
		view.addObject("processList", list);
		view.addObject("TestStr", "This is a test message.");
		return view;
	}


5. jsp
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<body>
${TestStr}
<c:forEach var="process" items="${processList}">
${process.name }
</c:forEach>
</body>

猜你喜欢

转载自panyongzheng.iteye.com/blog/2074554
今日推荐