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
       {
              }

           }

     
            

  • 相关阅读:
    CF # 296 C Glass Carving (并查集 或者 multiset)
    linux 基本命令
    为什么是丰田——丰田的七个习惯之习惯一
    关注C-RAN 的五大理由
    一个效果非常华丽的仿桌面APP,却胜似Launcher
    IOS6.0自带下拉刷新控件UIRefreshControl
    POJ 2421--Constructing Roads【水题 &amp;&amp; 最小生成树 &amp;&amp; kruskal】
    ORACLE-017:SQL优化-is not null和nvl
    数据结构——栈
    数据结构——静态链表
  • 原文地址:https://www.cnblogs.com/wangheblog/p/2713382.html
Copyright © 2011-2022 走看看