导读:
用于生成HTML 元素。用 创建超链接时,有两个优点:
1、容许在url中以多种方式包含请求参数。
2、当用户浏览器关闭Cookie时,会自动重写url,把SessionID作为请求参数包含在URL中,以跟踪用户会话。
属性:
forward :指定全局转发链接(使用struts-config.xml中的 元素中的 元素)
href:指定完整的URL链接
page:指定相对于当前网页的URL
1.创建全局转发链接
??
GLOBAL?LINK
标签中forward属性与 元素中的 元素匹配,以上代码生成
GLOBAL?LINK
2.创建完整的URL链接
BLOGJAVA
生成代码 :
BLOGJAVA
3.从当前网页创建相对URL
LOGIN
复选框,对应的ActionFormBean 中定义一个数组来接收
//formbean中定义数组
private?String?a[]?=?new?String[0];public?String[]?getA(){return?a[];}public?void?setA(String?arr[]){this.a?=?arr;}
被选中的复选框将值提交给ActionFormBean中的数组中,没选中的就不会包含
实现文件上传功能
1. jsp代码?
???
???
2. ActionFormBean
formbean中必须定义一个与页面 属性对应的属性file,且这个属性的类型为
org.apache.struts.upload.Formfile类型
import?javax.servlet.http.HttpServletRequest;import?org.apache.struts.action.*
import?org.apache.struts.upload.FormFile;public?class?FileActionForm?extends?ActionForm?{
private?FormFile?file;
public?ActionErrors?validate(ActionMapping?actionMapping,
HttpServletRequest?httpServletRequest)?{??????????
return?null}
public?void?reset(ActionMapping?actionMapping,HttpServletRequest?servletRequest)?{}
public?void?setFile(FormFile?file)?{this.file?=?file;}
public?FormFile?getFile()?{return?file;}
}
3.在action类中处理文件上传
public?class?FileAction?extends?Action?{
public?ActionForward?execute(ActionMapping?actionMapping,
ActionForm?actionForm,
HttpServletRequest?servletRequest,
HttpServletResponse?servletResponse)?{
FileActionForm?fileActionForm?=?(FileActionForm)?actionForm;
FormFile?file?=?fileActionForm.getFile();
try?{
InputStream?in?=?file.getInputStream();
OutputStream?out?=?new?FileOutputStream("d://"+new?String(file.getFileName().getBytes("utf-8")));
int?i=0???????????byte[]?buffer?=?new?byte[4096];
while((i?=?in.read(buffer,0,4096))!=-1){
out.write(buffer,0,i);
}
in.close();
out.close();
}?catch?(FileNotFoundException?ex)?{
}?catch?(IOException?ex)?{}
try?{
servletRequest.setAttribute("name",new?String(file.getFileName().getBytes("UTF-8"),"UTF-8"));
}?catch?(UnsupportedEncodingException?ex1)?{
}
servletRequest.setAttribute("size",Integer.toString(file.getFileSize()));
return?actionMapping.getInputForward();
}
}
检索JSP隐含对象,如request,session,response
//在页面显示session id号
显示ResourceBundle中的消息
显示邦定的、带变量的资源文件:
资源文件MyMessage.properties
hello?=?Hello,{0}
struts-config.xml
标签
页面显示结果:Hello,Dada
检索Web资源的内容,装载到一个JAVABEAN中。
属性:id?? 定义一个代表web资源的变量
name? web资源的路径
input 如果没设置则 id 定义的变量为字符型,如果设置则id 定义的变量为java.io.InputStrean
//file.jsp中的内容装载到一个变量中,scource就是这个变量的引用
//写出这个对象的内容
format属性格式化输出
输出Float型值?
如request.setAtrribute("floatvalue",Float.valueOf("3.14159"));
输出结果是 3.1416
输出日期型
request.setAtrribute("date",Calendar.getInstance());
输出结果是 06-15-2006 10:12:35
filter属性
默认为true,把输出内容中的特殊html符号作为普通字符串来显示,如果为false,则不会
本文转自
http://www.blogjava.net/envoydada/archive/2006/03/28/37791.html
用于生成HTML 元素。用 创建超链接时,有两个优点:
1、容许在url中以多种方式包含请求参数。
2、当用户浏览器关闭Cookie时,会自动重写url,把SessionID作为请求参数包含在URL中,以跟踪用户会话。
属性:
forward :指定全局转发链接(使用struts-config.xml中的 元素中的 元素)
href:指定完整的URL链接
page:指定相对于当前网页的URL
1.创建全局转发链接
??
GLOBAL?LINK
标签中forward属性与 元素中的 元素匹配,以上代码生成
GLOBAL?LINK
2.创建完整的URL链接
BLOGJAVA
生成代码 :
BLOGJAVA
3.从当前网页创建相对URL
LOGIN
复选框,对应的ActionFormBean 中定义一个数组来接收
//formbean中定义数组
private?String?a[]?=?new?String[0];public?String[]?getA(){return?a[];}public?void?setA(String?arr[]){this.a?=?arr;}
被选中的复选框将值提交给ActionFormBean中的数组中,没选中的就不会包含
实现文件上传功能
1. jsp代码?
???
???
2. ActionFormBean
formbean中必须定义一个与页面 属性对应的属性file,且这个属性的类型为
org.apache.struts.upload.Formfile类型
import?javax.servlet.http.HttpServletRequest;import?org.apache.struts.action.*
import?org.apache.struts.upload.FormFile;public?class?FileActionForm?extends?ActionForm?{
private?FormFile?file;
public?ActionErrors?validate(ActionMapping?actionMapping,
HttpServletRequest?httpServletRequest)?{??????????
return?null}
public?void?reset(ActionMapping?actionMapping,HttpServletRequest?servletRequest)?{}
public?void?setFile(FormFile?file)?{this.file?=?file;}
public?FormFile?getFile()?{return?file;}
}
3.在action类中处理文件上传
public?class?FileAction?extends?Action?{
public?ActionForward?execute(ActionMapping?actionMapping,
ActionForm?actionForm,
HttpServletRequest?servletRequest,
HttpServletResponse?servletResponse)?{
FileActionForm?fileActionForm?=?(FileActionForm)?actionForm;
FormFile?file?=?fileActionForm.getFile();
try?{
InputStream?in?=?file.getInputStream();
OutputStream?out?=?new?FileOutputStream("d://"+new?String(file.getFileName().getBytes("utf-8")));
int?i=0???????????byte[]?buffer?=?new?byte[4096];
while((i?=?in.read(buffer,0,4096))!=-1){
out.write(buffer,0,i);
}
in.close();
out.close();
}?catch?(FileNotFoundException?ex)?{
}?catch?(IOException?ex)?{}
try?{
servletRequest.setAttribute("name",new?String(file.getFileName().getBytes("UTF-8"),"UTF-8"));
}?catch?(UnsupportedEncodingException?ex1)?{
}
servletRequest.setAttribute("size",Integer.toString(file.getFileSize()));
return?actionMapping.getInputForward();
}
}
检索JSP隐含对象,如request,session,response
//在页面显示session id号
显示ResourceBundle中的消息
显示邦定的、带变量的资源文件:
资源文件MyMessage.properties
hello?=?Hello,{0}
struts-config.xml
标签
页面显示结果:Hello,Dada
检索Web资源的内容,装载到一个JAVABEAN中。
属性:id?? 定义一个代表web资源的变量
name? web资源的路径
input 如果没设置则 id 定义的变量为字符型,如果设置则id 定义的变量为java.io.InputStrean
//file.jsp中的内容装载到一个变量中,scource就是这个变量的引用
//写出这个对象的内容
format属性格式化输出
输出Float型值?
如request.setAtrribute("floatvalue",Float.valueOf("3.14159"));
输出结果是 3.1416
输出日期型
request.setAtrribute("date",Calendar.getInstance());
输出结果是 06-15-2006 10:12:35
filter属性
默认为true,把输出内容中的特殊html符号作为普通字符串来显示,如果为false,则不会
本文转自
http://www.blogjava.net/envoydada/archive/2006/03/28/37791.html