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

           }

     
            

  • 相关阅读:
    开学测试感想
    动手动脑1(00JAVA语言基础)
    9.29 java web注释方式以及servlet映射
    三十道随机算法
    9.30 servlet学习
    C#验证控件的使用方法
    SqlHelper详解
    C#字符串的几种常用方法
    存储过程事务处理
    js url编码
  • 原文地址:https://www.cnblogs.com/wangheblog/p/2713382.html
Copyright © 2020-2023  润新知