zoukankan      html  css  js  c++  java
  • javaee strut2 第一回

    1.类Servlet API解析:{
           ActionContext类{
              ActionContext acx=Action.getContext();
             类Session: acx.getContext().getSession().put(key,value);
             类Request:acx.put(key,value);
             类Application:acx.getApplication().put(key,value);
                            }
                          }
    2.直接调用Servlet API:{
           实现三个接口:ServletResponseAware,
                         ServletRequestAware,
                         ServletContextAware
             定义三个数据:private HttpServletRequest request;
                           private HttpServletResponse response;
                           private ServletContext context;
            实现三个借口函数:
                            public void setServletContext(ServletContext context) {
      this.context=context;
      
     }
     public void setServletRequest(HttpServletRequest request) {
      this.request=request;
      
     }
     public void setServletResponse(HttpServletResponse response) {
      this.response=response;
      
     }
       实现了这三步便可自由调用Servlet API;
                      }
    3.动态调用(不同操作调用同一类里的不同函数):
    {
      View代码:
     <form action="Login.action" method="post">
       User:<input type="text" name="user" /><br/>
       Pwd: <input type="password" name="pwd" /><br/>
       <input type="submit" value="Submit" />
       <input type="button" value="注册" onclick="regin()"/>
       </form>
       <script type="text/javascript">
       function regin(){
      
       tagerForm=document.forms[0];
       tagerForm.action="Regin!regin.action";
       tagerForm.submit();
      
       }

    strut.xml代码:
    <action name="Login" class="actions.LoginAction">

    <result name="success">/success.jsp</result>
    <result name="fail">/fail.jsp</result>
    </action>
    <action name="Regin" class="actions.LoginAction" method="regin">
    <result name="success">/regin.jsp</result>

    Servlet代码:
        public class LoginAction
         {
        public String regin()
              {
      
      ActionContext.getContext().put("user", getUser());
      
      return "success";
        }
    public String execute() throws Exception
       {
              }

           }

     
            

  • 相关阅读:
    C# 对Excel文档打印时的页面设置
    C# 对Excel 单元格格式, 及行高、 列宽、 单元格边框线、 冻结设置
    object does not contain a definition for get_range
    shell变一些小技巧
    Codeforces Round #277.5 (Div. 2)A——SwapSort
    ActiveMQ与RabbitMQ采用camel综合
    SAP ABAP规划 使用LOOP READ TABLE该方法取代双LOOP内部表的方法
    Object-c中间initialize 与 辛格尔顿
    队列——阵列实现
    左右GNU Linux企业加密文件系统 eCryptfs简介
  • 原文地址:https://www.cnblogs.com/wangheblog/p/2713382.html
Copyright © 2011-2022 走看看