action中得到request,session和application屬性方法

          public String execute() throws Exception{//僅僅訪問添加用這個
                  ActionContext ac=ActionContext.getContext();
                  ac.getApplication().put(
          "app","應用范圍");
                  ac.getSession().put(
          "ses","session應用");
                  ac.put(
          "req""request范圍");
                  
          return "success"
              }

              
          public String rsa() throws Exception{//得到文件的絕對路徑用此方法
                  HttpServletRequest request = ServletActionContext.getRequest();
                  ServletContext servletContext 
          = ServletActionContext.getServletContext();
          //        servletContext.getRealPath("/index.html");得到文件的絕對路徑
          //        request.getSession();
          //        HttpServletResponse response = ServletActionContext.getResponse();
                  request.setAttribute("req""request范圍屬性");
                  request.getSession().setAttribute(
          "ses","session會話范圍屬性");
                  servletContext.setAttribute(
          "app","應用范圍屬性");
                  
          return "success";
                  
              }

          posted @ 2012-06-05 17:29 youngturk 閱讀(915) | 評論 (0)編輯 收藏

          struts2訪問屬性的添加..ActionContext,在excute執行方法中添加..

          public String execute() throws Exception{//在execute方法里面應用全局應用session
                  ActionContext ac=ActionContext.getContext();
                  ac.getApplication().put(
          "app","應用范圍");//往serviceContext里放入
                  ac.getSession().put("session","session應用");//往session里面放
                  ac.put("req""request范圍");//往req里面放..
                  return "success";
              }


          ActionContext ac = ActionContext.getContext();
          ac.

          posted @ 2012-06-05 16:28 youngturk 閱讀(554) | 評論 (0)編輯 收藏

          oracle本地網絡服務名配置

          1,用vpn可以登錄公司內網,當用戶名,密碼登錄上去了以后即現在的環境就是公司局域網的了
          可以配置:
          database.url=jdbc:oracle:thin:@11,21,123.0:1521:tianjin
          TJGWL61 =//網絡服務名,隨便
            (DESCRIPTION =
              (ADDRESS_LIST =
                (ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.5.61)(PORT = 1521))
              )
              (CONNECT_DATA =
                (SERVICE_NAME = tianjin),數據庫名
              )
            )

          posted @ 2012-06-05 13:53 youngturk 閱讀(1340) | 評論 (0)編輯 收藏

          struts2 請求參數值的獲得

          action文件:
          public class HelloWorldAction {//id=123&name=aaa
           private Integer id;
           private Person person;
           public Person getPerson() {
            return person;
           }


           public void setPerson(Person person) {
            this.person = person;
           }

          實體bean文件:
          public class Person {
          //需要默認構造器,struts2利用反射機制獲得值
           public String getName() {
            return name;
           }
           public void setName(String name) {
            this.name = name;
           }
           public Integer getId() {
            return id;
           }
           public void setId(Integer id) {
            this.id = id;
           }
           private String name;
           private Integer id;
          }
          瀏覽器請求頁面:
          <form action="<%=request.getContextPath() %>/control/department/helloWordexecute.action">
          <!--    <form action="/control/department/helloWordexecute.action"> -->
               name:<input type="text" name="person.name">
               id:<input type="text" name="person.id">
               <input type="submit" value="send">
             </form>
          接受實體bean 值文件:

          <body>
             id=${person.id}<br>
             name=${person.name}

            </body>


          posted @ 2012-06-05 10:23 youngturk 閱讀(856) | 評論 (2)編輯 收藏

          struts,表單form中對應到action付值的獲得

          package cn.itcast.action;

          import java.net.URLEncoder;

          public class HelloWorldAction {//id=123&name=aaa
              private Integer id;
              
          public Integer getId() {
                  
          return id;
              }



              
          public void setId(Integer id) {
                  
          this.id = id;
              }



              
          public String getName() {
                  
          return name;
              }



              
          public void setName(String name) {
                  
          this.name = name;
              }


              
          private String name;
              
          private String msg;
              
          private String username;
              
          private String savepath;
              
              
          public String getSavepath() {
                  
          return savepath;
              }


          //    struts2會自動獲struts.xml配置文件中parameter付值變量信息值
              public void setSavepath(String savepath) {
                  
          this.savepath = savepath;
          //        <action name="helloWord*" class="cn.itcast.action.HelloWorldAction" method="{1}" >
              
          //        <param name="savepath">/department</param>
              
          //        <result name="success">/WEB-INF/page/message.jsp</result>
          //        </action>
              }



              
          public String getUsername() {
                  
          return username;
              }


          //    struts2會自動獲得對應表單提交的字段信息,例如form中有username
              public void setUsername(String username) {
                  
          this.username = username;
              }



              
          public String getMessage() {
                  
          return msg;
              }

              
          public String addUI(){
                  msg 
          = "addUI";
                  
          return "success";
              }



              
          public String execute() throws Exception{
                  
          //this.username = URLEncoder.encode("傳智播客", "UTF-8");
                  this.username = "firest";
                  
          this.msg = "我的第一個struts2應用";
                  
          return "success";
              }

              
              
          public String add(){
                  
          return "message";
              }

          }

          posted @ 2012-06-05 09:59 youngturk| 編輯 收藏

          action管理方式

          1struts.action.extension可以修改請求后綴
          在struts.xml中使用
          <constant name="struts.action.extension" value="do,action"/>
          struts.xml中和struts.properties中可以配置常量,最好在struts.xml中定義
          struts-default.xml
          struts-plugin.xml
          struts.xml
          struts.properties
          web.xml
          重復定義常量,后面的常量值會覆蓋前面的常量

          2<constantname="struts.i18n.encoding" value="UTF-8"/>
          參數作用于setCharacterEncoding方法 freemarker的輸出

          系統自動重新加載
          <constantname = "struts.configuration.xmlreload"/>

          創建spring負責創建actin對象
          <constantname = "struts.objectFactory"/>
          限制上傳文件大小
          <constantname = "struts.multipart.maxSize" value="10838274"/>
          3處理流程 action的管理方式
          用戶請求--》strutsprepareAndExecuteFilter---》
          inerceptor,struts2d內置的一些攔截器---》
          用戶編寫action類---》result進行跳轉---》jsp、html---》瀏覽器響應
          包唯一的
          4,指定多個struts文件
          <struts>

          <constant name="struts.action.extension" value="do,action"/>
              <include file="department.xml" />
              <include file="employee.xml" />
             
          </struts>
          employee.xml如下:
          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE struts PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
              "http://struts.apache.org/dtds/struts-2.0.dtd">

          <struts>
              <package name="employee" namespace="/control/employee" extends="struts-default">
                  <action name="helloWord" class="cn.itcast.action.HelloWorldAction" method="execute" >
                      <param name="savepath">/employee</param>
                      <result name="success">/WEB-INF/page/message.jsp</result>
                  </action>
                      
              </package>
          </struts>

          posted @ 2012-06-04 23:04 youngturk 閱讀(216) | 評論 (0)編輯 收藏

          觸發器 trigger

          create or replace trigger tr_in
            before insert on doptin  
            
          for each row
          declare
            v_count number;
            
            
          -- local variables here
          begin
            select count(
          *) into v_count from dopt 
            where doptid 
          =:new.proid;
            
            
          if v_count =0 then
              insert into dopt(非變異表) values(sq_dopt.nextval,:
          new.proid,:new.innum);
            
          else
              update dopt set dopt.doptnum 
          = doptnum+:new.innum where proid = :new.proid;
            end 
          if;
            
          --檢測是否第一次入庫記錄,如果第一次入庫,則在dopt表中
            
          --建立一條記錄,否則修改dopt表中庫存數量
            exception when others then
              dbms_output.put_line(sqlerrm);
          end tr_in;


          --------------------


          create or replace trigger tr_out
            before insert on doptout  
          --觸發表
            
          for each row
          declare
            v_num number;
            
          -- local variables here
          begin
            select dopt.doptnum into v_num from dopt where dopt.proid 
          = :new.proid;
            
          if :new.outnum > v_num then
              raise_application_error(
          -20001,'庫存不足');
            
          else
              update dopt set doptnum 
          = doptnum - :new.outnum where doptid = :new.proid;
            end 
          if;
          end tr_out;



          ---------------------------------------
          --1觸發事件 insert delete update
          --2觸發時機
          --對dml語句之前還是之后讓他工作
          --3觸發表,觸發器為之工作的表
          --4觸發類型:
          -- 4.1行級,語句級觸發器即(表級觸發器)
          create or replace trigger tr_row_after
            after update on emp  
            
          for each row
          declare
            
          -- local variables here
          begin
            dbms_output.put_line(
          '××行級后觸發器工作××');
          end tr_row_after; 

          -------------------
          create or replace trigger tr_row_before
            before update on emp  
            
          for each row
          declare
            
          -- local variables here
          begin
            dbms_output.put_line(
          'row before trigger test');
          end tr_row_before;
          ----------------------------------------
          create or replace trigger tr_tab_before
            before update on emp  
            
          declare
            
          -- local variables here
          begin
            dbms_output.put_line(
          'table  grade before working');
          end tr_tab_before;
          -------------------------
          create or replace trigger tr_tab_after
            before update on emp  
            
          declare
            
          -- local variables here
          begin
            dbms_output.put_line(
          'table  grade after working');
          end tr_tab_after;
          ------------------------------------------執行結果:
          table  grade after working
          table  grade before working
          row before trigger test
          row after trigger test
          row before trigger test
          row after trigger test
          row before trigger test
          row after trigger test
          ----------------------
          -----------觸發操作(觸發器中語句塊
          ---周末不能對員工表做操作

          create or replace trigger tr_emp2_in_up_de
            before insert or update or delete on emp2  
            
          declare
            v_day varchar2(
          20);
            
          -- local variables here
          begin
            select to_char(sysdate,
          'dy') into v_day from dual;

              
          if inserting then
                  raise_application_error(
          -20001,'have the rest day can not control employ');
              elseif updating then
                  raise_application_error(
          -20001,'have the rest day not control employ');
              elseif deleting then
                  raise_application_error(
          -20001,'have the rest day cnot control employ');
              end 
          if;

          end tr_emp2_in_up_de;
          ---------觸發器執行
          --ml操作請求---》觸發器工作---》dml操作結束----》commit or roback
          --觸發器不能還有事務控制語句;commit roback
          ---不能含有ddl語句,因為ddl語句會自動提交;
          ---觸發器代碼大小不能超過512k,可以使用觸發器調用過程或者函數調用,解決較大代碼調用問題
          ---注意,觸發器都是在dml結束前執行 ,delete中 :old指刪除的要操作de舊記錄,insert中:new指要插入的新記錄
          --after,與 before觸發器的區別,update即可以:new,又可以:old,他們只能在行集觸發器中使用..
          --行級before觸發器可以修改:new的值,而行級后after觸發器則不行
          --1觸發時機,before比after先執行,
          --2-定義取編號觸發器
          create or replace trigger tr_teb_before
            before insert on teb  
            
          for each row
          declare
            
          -- local variables here
            v_num number;
          begin
             select sq_teb.nextval into v_num from dual;
             :
          new.tebid := v_num;
          end tr_teb_before;
          ---instead of 觸發器 視圖觸發器 做修改操作,視圖只是用來查詢的,一旦用修改則用instead of觸發器
          ---多表復雜視圖 不能通過dml操作修改,
          --和普通dml觸發器的區別:instead of 操作會中斷dml操作
          --普通觸發器是dml操作事務的一部分
          --instead of觸發器會結束當前dml操作
          --dml操作請求(即dml操作結束)---》instead of觸發器工作, set serveroutput on;insert into v_teb2 values(1,'a');
          create or replace trigger tr_teb2
            instead of insert on v_teb2  
            
          for each row
          declare
            
          -- local variables here
          begin
            dbms_output.put_line(
          'instead of trigger working');
            insert into teb2 values(sq_teb.nextval,
          'trigger working');
          end tr_teb2;

          ----約束表,觸發表,觸發器工作的表,example:部門表就是員工表的約束表
          ----變異表,就是dml操作過程的觸發表
          ----舊數據--臟數據--》新數據
          ---long double 8b  1101 0100 -----1021 2121----->1200 1323
          ----DML開始操作--》行級觸發器工作---》end結束操作。
          ----每個部門最多6人,6人后,不允許往這個部門添加員工,和修改其他部門為這個部門員工
          ----行級觸發器不能讀取變異表,
          ---觸發表:對于觸發器而言,就是觸發器為之定義的表
          ----變異表:就是當前dml操作所影響的表(經常來說觸發表就是變異表)
          create or replace trigger tri_emp
            before insert or update on emp3   
            
          for each row
          declare
            
          -- local variables hereer
            v_count number;
          begin
            select count(
          *) into v_count from emp3(本表:(即變異表行級觸發器不允許讀取)) where emp3.deptno = :new.deptno;
            
          if v_count >= 6 then
              raise_application_error(
          -20001,'every dept can not over 6 peaple');
            end 
          if;
          end tri;

          ---矛盾;行級觸發器不允許查詢變異表,而表級觸發器不允許使用:new
          ----解決方案:
          --1,建立包,定義一個共同變量,用來存放部門編號變量
          create or replace 
          package pak_deptno is
            v_deptno number;
          end pak_deptno;
          --2,建立一個行級前或者后觸發器,僅僅將操作行的部門編號放入包中。
          create or replace trigger tri_row_emp3
            after insert or update on emp3   
            
          for each row
          declare
           
          begin
            pak_deptno.v_deptno:
          =:new.deptno;
          end tri_row_emp3;
          --3,建立一個表級后觸發器中查詢變異表,來確定是否可以添加.
          create or replace trigger tri_table_emp
            after insert or update on emp3   
          declare
            
          -- local variables hereer
            v_count number;
          begin
            select count(
          *) into v_count from emp3 where emp3.deptno = pak_deptno.v_deptno;
            
          if v_count >= 6 then
              raise_application_error(
          -20001,'every dept can not over 6 peaple');
            end 
          if;
          end tri_table_emp;


          ----如果是一條insert語句,僅僅插入一行記錄,則oracle中行級觸發器允許查詢變異表..
          ---insert into emp3 select * from emp where deptno=10;

          posted @ 2012-06-03 23:06 youngturk 閱讀(296) | 評論 (0)編輯 收藏

          創建觸發器trigger原創

          create or repalce 泰森 on 霍利菲爾德
          before 出拳
          as
          咬他耳朵.

          posted @ 2012-06-01 22:20 youngturk 閱讀(202) | 評論 (0)編輯 收藏

          redirect

          redirect重定向的路徑不能在WEB-INF目錄下,WEB-INF目錄下使用的是dispatcher跳轉.
          example:
          登錄頁面,用戶登錄錯誤時候,采用重定向redirect方式,返回到登錄界面
          plaintext定向視圖時候將視圖源碼輸出
          <action name="redirect"> <!-- 默認class為 ActionSurport 默認 方法為excute result默認值是success -->
                   <result type="redirect">/redirect.jsp?username=${username}</result><!-- 默認請求轉發類似    dispatcher -->
           </action>

          posted @ 2012-05-31 16:05 youngturk 閱讀(167) | 評論 (0)編輯 收藏

          第一個宏定義 <#macro statusInfo main=main>

          <#macro statusInfo  main=main> statusInfo表示宏的名字,左邊的main表示型參(為以后在宏中應用),右邊的main表示實參(也就是java實際返回的變量名字)
          </#macro>

          posted @ 2012-05-30 09:11 youngturk 閱讀(207) | 評論 (0)編輯 收藏

          僅列出標題
          共33頁: First 上一頁 12 13 14 15 16 17 18 19 20 下一頁 Last 
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          公告

          this year :
          1 jQuery
          2 freemarker
          3 框架結構
          4 口語英語

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          EJB學習

          Flex學習

          learn English

          oracle

          spring MVC web service

          SQL

          Struts

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 石嘴山市| 云龙县| 寿阳县| 长武县| 壶关县| 舟曲县| 德阳市| 佛教| 桐柏县| 双江| 通化市| 日照市| 桐梓县| 和政县| 甘孜| 石河子市| 玛沁县| 宣武区| 天台县| 灌云县| 邯郸县| 五大连池市| 腾冲县| 江永县| 清流县| 三都| 周口市| 金坛市| 关岭| 湖南省| 德惠市| 梓潼县| 吉林省| 远安县| 普兰店市| 新野县| 施甸县| 石泉县| 邢台县| 南宫市| 本溪市|