Spring的xml配置(extends MultiActiveController)

来源:互联网 发布:腾讯大数据研究中心 编辑:程序博客网 时间:2024/05/17 22:08

Spring的xml配置(extends MultiActiveController)

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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd          http://www.springframework.org/schema/aop    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd          http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd          http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context-3.0.xsd       http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><beanclass="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /><!-- ViewResolver --><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass"value="org.springframework.web.servlet.view.JstlView" /><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /></bean>      <bean id="urlMapping"          class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">          <property name="mappings">              <props>                <prop key="/login">loginController</prop>              </props>          </property>      </bean><bean id="paraMethodResolver"           class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">         <property name="paramName">            <value>action</value>        </property>         <property name="defaultMethodName">            <value>list</value>        </property>     </bean>             <bean id="loginController"           class="com.test.controller.LoginController">         <property name="methodNameResolver">             <ref bean="paraMethodResolver"/>         </property>     </bean></beans>  
success.jsp(WEB-INF/jsp下)

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!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=UTF-8"><title>Insert title here</title></head><body>Congratulations!<br />${notice}</body></html>

LoginController

package com.test.controller;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;import org.springframework.web.servlet.mvc.multiaction.MultiActionController;public class LoginController extends MultiActionController {public ModelAndView loginValidate(HttpServletRequest request,HttpServletResponse response) throws Exception {// TODO Auto-generated method stubModelAndView mv = new ModelAndView();mv.addObject("notice", "Hello World!");mv.setViewName("success");return mv;}}

部署,访问




0 0