Spring Web MVC 的HandlerMapping的使用之-------Simp...

来源:百度文库 编辑:神马文学网 时间:2024/07/05 12:26:58
使用背景:
第一步>>>
在包com.spring.web.controller下创建一个Controller: LoginConstroller
public class LoginController  extends AbstractController{
   
    public ModelAndView handleRequestInternal(HttpServletRequest request,
           HttpServletResponse response)throws Exception{
       
        String userName=request.getParameter("username");
        String pwd=request.getParameter("pwd");
       
        String msg="";
        ModelAndView mav=new ModelAndView("loginResult");        //注意要在/WEB-INF/jsp下面创建loginResult.jsp页面
        if(!userName.equals("liuxi")){
            msg="用户名不存在!";
        }else if(!pwd.equals("8888")){
            msg="密码不正确!";   
           
        }else{
            msg="恭喜您登录成功!";
        }
       
       
        mav.addObject("msg",msg);
        return mav;
    }}第二步>>>>
配置web.xml:

    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   
   
   
       sample
       org.springframework.web.servlet.DispatcherServlet
      
   

   
   
       sample
       *.do
   

   
 
    index.jsp
 

第三步>>>>
配置sample-servlet.xml:
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
   
  
  
 
  
  
 
          
      

   
   -->
  
    
       
           loginController
       

    

 

 
  
     /WEB-INF/jsp/
     .jsp
    
      
        org.springframework.web.servlet.view.JstlView
      

    

  
 
  
  
 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/liuxiIT/archive/2010/07/06/5715395.aspx