• JAVAWEB 一一SpringMVC(XML配置)


    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    	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">
      <display-name></display-name>	
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      
     <listener>
      	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener> 
      
      <servlet>
      	<servlet-name>springmvc</servlet-name>
      	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      	<load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
      	<servlet-name>springmvc</servlet-name>
      	<url-pattern>*do</url-pattern>
      </servlet-mapping>
    </web-app>
    

     springmvc-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" 
        xmlns:mvc="http://www.springframework.org/schema/mvc" 
        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.2.xsd 
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-4.2.xsd 
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd 
            http://www.springframework.org/schema/task 
            http://www.springframework.org/schema/task/spring-task-4.2.xsd">
     	
     	<!-- 简单url地址处理器映射 --> 
        <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > 
            <property name="mappings"> 
                <props> 
                    <prop key="/login.do">userController</prop> 
                </props> 
           </property>
        </bean> 
        <bean name ="userController" class="com.springmvc.controller.UserController">
        	<property name="userService" ref="userService"></property>
        </bean>
        <bean id="userService" class="com.springmvc.service.UserServiceImpl"/>
        <!-- 视图解析器-->
        <!--  /WEB-INF/jsp/success.jsp -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/jsp/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    </beans>
    

      

    controller

    package com.springmvc.controller;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;
    
    import com.springmvc.service.UserService;
    
    public class UserController implements Controller {
    	
    	private UserService userService;
    	public ModelAndView handleRequest(HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		String username = request.getParameter("username");
    		String password = request.getParameter("password");
    		boolean islogin = userService.login(username, password);
    		
    /*
     * 		可以自己建对象 传数据到页面 
     * 		List<Object>list = new ArrayList<Object>();
    		list.add(1);
    		list.add(1);
    		list.add(1);
    		list.add(1);
    		
    		ModelAndView mv = new ModelAndView();
    		mv.setViewName("success");
    		
    				
    		list.add("t");
    		list.add("te");
    		list.add("tes");
    		list.add("test");
    		mv.addObject("list",list);*/
    		
    		
    		if(islogin){
    			return new ModelAndView("success");
    			//return mv;
    		}else{
    			return new ModelAndView("login");
    		}
    	}
    	public UserService getUserService() {
    		return userService;
    	}
    	public void setUserService(UserService userService) {
    		this.userService = userService;
    	}
    	
    }
    

      

  • 相关阅读:
    (转)viso 形状搜索 无法使用 的解决办法
    Visio 2003 直线需要相交时的设置方法
    C# Serialport执行close()方法时,程序卡死的解决办法
    RabbitMQ核心技术总结
    kafka核心原理总结
    hadoop的价值在哪里
    从程序员小仙飞升上神,java技术开发要如何实现?
    明年大数据行业的趋势会是哪些?
    2016年末程序员应该知道的基本架构思想
    2016年末程序员突破自我的绝密方法分享
  • 原文地址:https://www.cnblogs.com/PoeticalJustice/p/7816359.html
Copyright © 2020-2023  润新知