eb.xml中配置一个上下文载入器ContextLoaderListener或者ContextLoaderServlet,我们这里为了兼容版本较低的Serlvet容器(实际上我采用的2.4),采用第二种:
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
这样就全部配置完毕了,当然,上面的ntx.xml是我在项目完成以后才配置完成的,这里不再多讲,有bean元素的配置大家可以参考有关资料理解,很容易理解的,下面再给出完整的web.xml配置以及java<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ntx.xml</param-value>
</context-param>
<servlet>
<servlet-name>ntx</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ntx</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
根据ntx.xml知道,总共有三个java文件,LoginController.java是控制器,继承了最简单的Controller(实际上spring有很多控制器供我们选择),接下来是一个简单控制器的源码:
/** *//**
* program NtxSpring
* date 2006-9-27
* @author 张逸轩
*/
package ntx.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 ntx.service.LoginService;
/** *//**@spring.bean id="loginController"
* @spring.property name="gotoUrl" value="/showResult.jsp"
* @spring.property name="loginService" ref="loginService"
*/
/** *//**
* 作用描述:spring示例
*
* 说明:spring示例,以上的spring标签方便使用xdoclet生成spring配置文件
*
* @author 张逸轩
* Copyright(c)2006 cleverfox
*/
public class LoginController implements Controller...{
private LoginService loginService ;
private String gotoUrl;
public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception ...{
String userName = request.getParameter("userName");
this.getUserInfo(request, userName);
return new ModelAndVi
|