zoukankan      html  css  js  c++  java
  • 一些重要的常量和工具类在 Spring3 和 Struts2 中

    1.    org.springframework.web.context.WebApplicationContext.ROOT // spring 从 web.xml 启动后注册到 ServletContext 中

    2.    // spring 在 web.xml 中启动加载代码
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    3.    // spring 在 web.xml 中字符编码过滤器
    <filter>
      <filter-name>CharacterEncodingFilter</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
      </init-param>
    </filter>
    <filter-mapping>
      <filter-name>CharacterEncodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

    4.    ActionContext // Action 执行上下文
    代码 ActionContext context = ActionContext.getContext();
    Map params = context.getParameters();
    String username = (String) params.get(“username”);
    ActionContext 线程安全

    5.    ServletActionContext
    直接继承ActionContext,可以和Web容器直接打交道获得Servlet相关的所有对象

    public class LoginAction extends ActionSupport { 
     
        public String login() {                             // 登录方法 
            HttpServletRequest request = ServletActionContext.getRequest();
    // 获取request 
            HttpServletResponse response = ServletActionContext.getRe 
            sponse();                                       // 获取response 
     
            HttpSession session = request.getSession(true); // 获取Session 
            session.setAttribute("account", account);       // 放到 Session 中 
     
            ServletContext context = ServletActionContext.getServletContext();
    // 获取上下文 

    6.    ActionSupport

    7.    WebApplicationContextUtils
    Spring 用来web项目中获得ApplicationContext

    8.    EventDispatchAction 与 Struts 2中的action!method.action
    当然,我们也可以模拟EventDispatchAction的方法通过request获得和处理参数信息。但这样比较麻烦。在Struts2中提供了另外一种方法,使得无需要配置可以在同一个action类中执行不同的方法(默认执行的是execute方法)。使用这种方式也需要通过请求参来来指定要执行的动作。请求参数名的格式为:action!method.action
    <s:form action="submit.action" >
            <s:textfield name="msg" label="输入内容"/> 
            <s:submit name="save" value="保存" align="left" method="save"/>
            <s:submit name="print" value="打印" align="left" method="print" />     
        </s:form>
  • 相关阅读:
    无法生成DH密钥对Could not generate DH keypair
    《细节决定成败》 汪中求著
    《老马的职业“鬼”话》 马华兴著
    《生命不息,折腾不止》 罗永浩著
    《你的生命有什么可能》 古典老师 著
    《拆掉思维里的墙》 古典老师 著
    Linux命令应用大词典-第46章 其他命令
    Linux命令应用大词典-第45章 服务器配置
    Linux命令应用大词典-第44章 PPPoE配置
    Linux命令应用大词典-第43章iptables和arptables防火墙
  • 原文地址:https://www.cnblogs.com/nysanier/p/2074759.html
Copyright © 2011-2022 走看看