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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="com.wodwl.controller" />
<!-- 视图 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 使用标签库,暂时可不用 -->
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> -->
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Controller控制器
package com.wodwl.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class UserController {
private String add_view="user/add";
private String display_view="user/display";
private String list_view;
private String update_view;
public String getAdd_view() {
return add_view;
}
public void setAdd_view(String add_view) {
this.add_view = add_view;
}
public String getDisplay_view() {
return display_view;
}
public void setDisplay_view(String display_view) {
this.display_view = display_view;
}
public String getList_view() {
return list_view;
}
public void setList_view(String list_view) {
this.list_view = list_view;
}
public String getUpdate_view() {
return update_view;
}
public void setUpdate_view(String update_view) {
this.update_view = update_view;
}
@RequestMapping(value="/admin/user.do")
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
Map model = new HashMap();
model.put("msg", "hello nice to 带加号");
return new ModelAndView(getAdd_view(), model);
}
@RequestMapping(value="/hello/world.do")
public ModelAndView get(){
Map modelMap=new HashMap();
modelMap.put("msg","hello world");
return new ModelAndView(getDisplay_view(),modelMap);
}
}