随笔 - 37  文章 - 14  trackbacks - 0
<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿

随笔分类

随笔档案

文章分类

相关链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜

1. web.xml中还是

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/conf/spring/**/*-context.xml</param-value>
 </context-param>

2. portal-context.xml中的一段

<bean
      id="customerInfoServlet"
      class="chances.card.portal.customer.CustomerInfoServlet"
  >

    <property name="infoPage">

      <value>${portal.card.info.index}</value>
    </property>
    <property name="customerLoginUrl">

      <value>${portal.card.loginUrl}</value>
    </property>
    <property name="cardSearcher">

      <ref bean="cardSearcher"/>
    </property>
    <property name="cardManager">

      <ref bean="cardManager"/>
    </property>

  </bean>

3. web.xml 中的一段配置

<servlet>
  <servlet-name>customerLogin</servlet-name>
  <servlet-class>
   chances.card.commons.servlet.proxy.SpringServletProxy
  </servlet-class>
  <init-param>
   <param-name>beanName</param-name>
   <param-value>customerLoginServlet</param-value>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>customerLogin</servlet-name>
  <url-pattern>/customerLogin</url-pattern>
 </servlet-mapping>

----------------------------最早的servlet 的配置方法

<servlet>
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<description>A test Servlet</description>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>

4. SpringServletProxy .java 类的代码

/**
 * Created on 2007-08-16
 *
 * $Id $
 * $Source $
 * $Revision $
 */
package chances.card.commons.servlet.proxy;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import chances.commons.web.SpringWebUtils;

/**
 * Servlet代理
 *
 * @author <a href="mailto:hjd_668@126.com">Alpha</a>
 * @version 1.0
 *
 */
public class SpringServletProxy extends HttpServlet {

    private static final long serialVersionUID = -5712473045972662420L;

    Servlet target;

    /**
     * (non-javadoc)
     *
     * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
    protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
            throws ServletException, IOException {
        target.service(arg0, arg1);
    }

    /**
     * (non-javadoc)
     *
     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        String name = config.getInitParameter("beanName");
        Object obj = SpringWebUtils.getBean(config.getServletContext(), name);
        if (obj instanceof Servlet) {
            target = (Servlet) obj;
        } else {
            throw new IllegalArgumentException(name);
        }
        target.init(config);
    }

    /**
     * (non-javadoc)
     *
     * @see javax.servlet.GenericServlet#destroy()
     */
    public void destroy() {
        super.destroy();
        target.destroy();
    }
}

posted on 2007-08-18 11:22 扭曲的铅笔 阅读(428) 评论(0)  编辑  收藏 所属分类: Spring

只有注册用户登录后才能发表评论。


网站导航: