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

public String rsa() throws Exception
{//得到文件的絕對(duì)路徑用此方法
HttpServletRequest request = ServletActionContext.getRequest();
ServletContext servletContext = ServletActionContext.getServletContext();
// servletContext.getRealPath("/index.html");得到文件的絕對(duì)路徑
// request.getSession();
// HttpServletResponse response = ServletActionContext.getResponse();
request.setAttribute("req", "request范圍屬性");
request.getSession().setAttribute("ses","session會(huì)話范圍屬性");
servletContext.setAttribute("app","應(yīng)用范圍屬性");
return "success";
}
1,用vpn可以登錄公司內(nèi)網(wǎng),當(dāng)用戶名,密碼登錄上去了以后即現(xiàn)在的環(huán)境就是公司局域網(wǎng)的了
可以配置:
database.url=jdbc:oracle:thin:@11,21,123.0:1521:tianjin
TJGWL61 =//網(wǎng)絡(luò)服務(wù)名,隨便
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.138.5.61)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = tianjin),數(shù)據(jù)庫(kù)名
)
)
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;
}
實(shí)體bean文件:
public class Person {
//需要默認(rèn)構(gòu)造器,struts2利用反射機(jī)制獲得值
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;
}
瀏覽器請(qǐng)求頁(yè)面:
<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>
接受實(shí)體bean 值文件:
<body>
id=${person.id}<br>
name=${person.name}
</body>
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會(huì)自動(dòng)獲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會(huì)自動(dòng)獲得對(duì)應(yīng)表單提交的字段信息,例如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 = "我的第一個(gè)struts2應(yīng)用";
return "success";
}

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

1struts.action.extension可以修改請(qǐng)求后綴
在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
重復(fù)定義常量,后面的常量值會(huì)覆蓋前面的常量
2<constantname="struts.i18n.encoding" value="UTF-8"/>
參數(shù)作用于setCharacterEncoding方法 freemarker的輸出
系統(tǒng)自動(dòng)重新加載
<constantname = "struts.configuration.xmlreload"/>
創(chuàng)建spring負(fù)責(zé)創(chuàng)建actin對(duì)象
<constantname = "struts.objectFactory"/>
限制上傳文件大小
<constantname = "struts.multipart.maxSize" value="10838274"/>
3處理流程 action的管理方式
用戶請(qǐng)求--》strutsprepareAndExecuteFilter---》
inerceptor,struts2d內(nèi)置的一些攔截器---》
用戶編寫action類---》result進(jìn)行跳轉(zhuǎn)---》jsp、html---》瀏覽器響應(yīng)
包唯一的
4,指定多個(gè)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>
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;
--檢測(cè)是否第一次入庫(kù)記錄,如果第一次入庫(kù),則在dopt表中
--建立一條記錄,否則修改dopt表中庫(kù)存數(shù)量
exception when others then
dbms_output.put_line(sqlerrm);
end tr_in;
--------------------
create or replace trigger tr_out
before insert on doptout --觸發(fā)表
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,'庫(kù)存不足');
else
update dopt set doptnum = doptnum - :new.outnum where doptid = :new.proid;
end if;
end tr_out;
---------------------------------------
--1觸發(fā)事件 insert delete update
--2觸發(fā)時(shí)機(jī)
--對(duì)dml語(yǔ)句之前還是之后讓他工作
--3觸發(fā)表,觸發(fā)器為之工作的表
--4觸發(fā)類型:
-- 4.1行級(jí),語(yǔ)句級(jí)觸發(fā)器即(表級(jí)觸發(fā)器)
create or replace trigger tr_row_after
after update on emp
for each row
declare
-- local variables here
begin
dbms_output.put_line('××行級(jí)后觸發(fā)器工作××');
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;
------------------------------------------執(zhí)行結(jié)果:
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
----------------------
-----------觸發(fā)操作(觸發(fā)器中語(yǔ)句塊
---周末不能對(duì)員工表做操作
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;
---------觸發(fā)器執(zhí)行
--ml操作請(qǐng)求---》觸發(fā)器工作---》dml操作結(jié)束----》commit or roback
--觸發(fā)器不能還有事務(wù)控制語(yǔ)句;commit roback
---不能含有ddl語(yǔ)句,因?yàn)閐dl語(yǔ)句會(huì)自動(dòng)提交;
---觸發(fā)器代碼大小不能超過(guò)512k,可以使用觸發(fā)器調(diào)用過(guò)程或者函數(shù)調(diào)用,解決較大代碼調(diào)用問(wèn)題
---注意,觸發(fā)器都是在dml結(jié)束前執(zhí)行 ,delete中 :old指刪除的要操作de舊記錄,insert中:new指要插入的新記錄
--after,與 before觸發(fā)器的區(qū)別,update即可以:new,又可以:old,他們只能在行集觸發(fā)器中使用..
--行級(jí)before觸發(fā)器可以修改:new的值,而行級(jí)后after觸發(fā)器則不行
--1觸發(fā)時(shí)機(jī),before比after先執(zhí)行,
--2-定義取編號(hào)觸發(fā)器
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 觸發(fā)器 視圖觸發(fā)器 做修改操作,視圖只是用來(lái)查詢的,一旦用修改則用instead of觸發(fā)器
---多表復(fù)雜視圖 不能通過(guò)dml操作修改,
--和普通dml觸發(fā)器的區(qū)別:instead of 操作會(huì)中斷dml操作
--普通觸發(fā)器是dml操作事務(wù)的一部分
--instead of觸發(fā)器會(huì)結(jié)束當(dāng)前dml操作
--dml操作請(qǐng)求(即dml操作結(jié)束)---》instead of觸發(fā)器工作, 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;
----約束表,觸發(fā)表,觸發(fā)器工作的表,example:部門表就是員工表的約束表
----變異表,就是dml操作過(guò)程的觸發(fā)表
----舊數(shù)據(jù)--臟數(shù)據(jù)--》新數(shù)據(jù)
---long double 8b 1101 0100 -----1021 2121----->1200 1323
----DML開始操作--》行級(jí)觸發(fā)器工作---》end結(jié)束操作。
----每個(gè)部門最多6人,6人后,不允許往這個(gè)部門添加員工,和修改其他部門為這個(gè)部門員工
----行級(jí)觸發(fā)器不能讀取變異表,
---觸發(fā)表:對(duì)于觸發(fā)器而言,就是觸發(fā)器為之定義的表
----變異表:就是當(dāng)前dml操作所影響的表(經(jīng)常來(lái)說(shuō)觸發(fā)表就是變異表)
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(本表:(即變異表行級(jí)觸發(fā)器不允許讀取)) 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;
---矛盾;行級(jí)觸發(fā)器不允許查詢變異表,而表級(jí)觸發(fā)器不允許使用:new。
----解決方案:
--1,建立包,定義一個(gè)共同變量,用來(lái)存放部門編號(hào)變量
create or replace package pak_deptno is
v_deptno number;
end pak_deptno;
--2,建立一個(gè)行級(jí)前或者后觸發(fā)器,僅僅將操作行的部門編號(hào)放入包中。
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,建立一個(gè)表級(jí)后觸發(fā)器中查詢變異表,來(lái)確定是否可以添加.
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語(yǔ)句,僅僅插入一行記錄,則oracle中行級(jí)觸發(fā)器允許查詢變異表..
---insert into emp3 select * from emp where deptno=10;
create or repalce 泰森 on 霍利菲爾德
before 出拳
as
咬他耳朵.
redirect重定向的路徑不能在WEB-INF目錄下,WEB-INF目錄下使用的是dispatcher跳轉(zhuǎn).
example:
登錄頁(yè)面,用戶登錄錯(cuò)誤時(shí)候,采用重定向redirect方式,返回到登錄界面
plaintext定向視圖時(shí)候?qū)⒁晥D源碼輸出
<action name="redirect"> <!-- 默認(rèn)class為 ActionSurport 默認(rèn) 方法為excute result默認(rèn)值是success -->
<result type="redirect">/redirect.jsp?username=${username}</result><!-- 默認(rèn)請(qǐng)求轉(zhuǎn)發(fā)類似 dispatcher -->
</action>
<#macro statusInfo main=main> statusInfo表示宏的名字,左邊的main表示型參(為以后在宏中應(yīng)用),右邊的main表示實(shí)參(也就是java實(shí)際返回的變量名字)
</#macro>