struts2工作总结.docx
- 文档编号:6424450
- 上传时间:2023-01-06
- 格式:DOCX
- 页数:18
- 大小:23.54KB
struts2工作总结.docx
《struts2工作总结.docx》由会员分享,可在线阅读,更多相关《struts2工作总结.docx(18页珍藏版)》请在冰豆网上搜索。
struts2工作总结
Struts2开发总结
(注:
Struts2版本:
Struts2.1.6,数据库:
Oracle9i)
1、 若在前台页面使用orgl表达式:
必须定义:
<%@ page isELIgnored = "false" %>
使用:
${requestScope.count}来获取session中的值
2、日期和天气js脚本,如图下格式:
today=new Date();
var day; var date; var hello; var wel;
hour=new Date().getHours()
if(hour<6)hello=''
elseif(hour<9)hello=''
elseif(hour<12)hello=''
elseif(hour<14)hello=''
elseif(hour<17)hello=''
elseif(hour<19)hello=''
elseif(hour<22)hello=''
else{hello=''}
if(today.getDay()==0)day='星期日'
elseif(today.getDay()==1)day='星期一'
elseif(today.getDay()==2)day='星期二'
elseif(today.getDay()==3)day='星期三'
elseif(today.getDay()==4)day='星期四'
elseif(today.getDay()==5)day='星期五'
elseif(today.getDay()==6)day='星期六'
date=(today.getYear())+'年'+(today.getMonth()+1)+'月'+today.getDate()+'日';
document.write(hello);
/*
[CDATA[*/
MiniSite.Weather.print("Wealth");
/*]]>*/
3、 在jsp页面中显示action中的数据,不需要点击链接到action再返回页面中显示数据
第一步,写一个action类
第二步:
配置struts.xml文件,如:
第三步:
在sort1.jsp中遍历action方法为sort5list的结果集:
iterator value="sort5list" id="ctype" status="status"> ct_id= property value="ct_id"/>"> propertyvalue="ct_name"/>
iterator>
第四步:
在index.jsp中调用action为sort5list的方法
action name="sort5" executeResult="true"> iterator value="sort5list" id="ctype"> iterator>
action>
4、 Struts2超链接传参方式:
第一种:
nid= propertyvalue="nid"/>"> property value="ntitle"/>
第二种:
url id="Newsquerynew" action="querynew.action"> param name="request_locale">Newsquerynew param>
url>
a href="%{Newsquerynew}">最新文章
a>
第三种:
a href="newsAction.action">直接使用即可
a>
注意:
Struts2超链接标签 ahref=””>中的href属性是必选参数,否则在项目整合中可能会出现不明的标签异常。 5、 使用Struts2标签 iterator>循环遍历结果集: iterator value="sort5newslist"> property value="ntime"/>) iterator> 其中内嵌html语言, iterator>除了value属性外,还有可选属性id="" status="status",value属性是必选的 6、 格式化日期显示方法 或者 ,只需要改变 即可 必须定义: <%@ page import="java.text.SimpleDateFormat;"%> Body体中引用: <%SimpleDateFormats= new SimpleDateFormat("yyyy-MM-dd"); Datentime= new Date(); %><%=s.format(ntime)%> 7、 FCK网页编辑器的使用: <%@ taglib uri="/FCKeditor" prefix="FCK"%> 在body体中引用: editor id="ncontent" width="90%" height="320" fontNames="宋体;黑体;隶书;楷体;Arial;ComicSansMS;Courier New;Tahoma;TimesNewRoman;Verdana" imageBrowserURL="/fkctest/FCKeditor/editor/filemanager/browser/default/browser.html? Type=Image&Connector=connectors/jsp/connector" linkBrowserURL="/fkctest/FCKeditor/editor/filemanager/browser/default/browser.html? Connector=connectors/jsp/connector" flashBrowserURL="/fkctest/FCKeditor/editor/filemanager/browser/default/browser.html? Type=Flash&Connector=connectors/jsp/connector" imageUploadURL="/fkctest/FCKeditor/editor/filemanager/upload/simpleuploader? Type=Image" linkUploadURL="/fkctest/FCKeditor/editor/filemanager/upload/simpleuploader? Type=File" flashUploadURL="/fkctest/FCKeditor/editor/filemanager/upload/simpleuploader? Type=Flash"> editor> 3、 Struts2下拉菜单的使用 select name="ct_sid" list="ctypesonlist" listKey="ct_id" listValue="ct_name" theme="simple" headerKey="0" headerValue="一级栏目"> select> select name="ninvalidate" list="#{1: '是',2: '否'}" listKey="key" listValue="value" headerKey="0"> select> 属性注解: name是给Struts2 select>标签取名字,这个也是提交到action并保存到对应的数据库中的字段名所必须得参数;list是下拉选项数值;listKey是选项列表所对应的id,listValue是选项列表每个字段的名称;theme是自定义下拉框格式,headerkey是首选项的主键id,headerValue是首选项的字段名 4、 Struts2.1.6使用日期控件: 需要导入包: struts2-dojo-plugin-2.1.6.jar <%@ taglib uri="/struts-dojo-tags" prefix="sx"%> 在head体中加入: head /> 在body体中引用: datetimepicker name="ninvalidate_time" type="date" displayFormat="yyyy/MM/dd" value="%{'today'}"> datetimepicker> 属性注解: name是给 detetimepicker>标签取名,type为date日期类型,displayFormat格式化显示日期,value是获取时间值,value="%{'today'}"是获取当前系统时间 5、 Struts2隐藏域标签: hidden name="auditing" value="1"> hidden> 11、Struts2中form提交表单格式 form action="login" method="post" theme="simple" validate="true"> form> 在form中加入theme="simple"属性,就不会受Struts2 form>定义格式的影响 12、使用属性驱动取值 在action中将要输出的属性生成get和set方法,并将返回值定义为返回对象,如: private String ntitle;//标题 private String ncontent;//内容 private String ntime;//时间 private String username;//发布人 Newsnews=ns.queryNnewsdetailsql2(nid);//返回一个对象 public StringgetNtitle(){ return ntitle; } public void setNtitle(Stringntitle){ this.ntitle =ntitle; } public StringgetNcontent(){ return ncontent; } public void setNcontent(Stringncontent){ this.ncontent =ncontent; } public StringgetNtime(){ return ntime; } public void setNtime(Stringntime){ this.ntime =ntime; } public StringgetUsername(){ return username; } public void setUsername(Stringusername){ this.username =username; } 由action直接跳转到要显示这些属性详细内容的页面 在jsp中直接使用标签 property value="ncontent"/>取出即可 使用模型驱动: 查改 新建action查询文章类型: import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import com.txxw.cms.news.model.Ctype; import com.txxw.cms.news.model.CtypeService; /** * @author fejd E-mail: lzd_niit_java@ * @version 创建时间: May 22, 2009 1: 43: 21 PM * 功能实现: 文章类型修改内容查询 */ public class CtypeeditAction extends ActionSupport implements ModelDriven{ private Ctype ctype=new Ctype();//将封装数据的ctype实现get和set方法 @Override public Stringexecute() throws Exception{ // TODO Auto-generatedmethodstub] HttpServletRequestrequest=ServletActionContext.getRequest(); int ct_id=Integer.parseInt(request.getParameter("ct_id").replace(",", ""));//通过选择复选框来实现单个文章类型修改 CtypeServicecs=new CtypeService(); Ctypectype=cs.editctypesql(ct_id); this.setCtype(ctype); return "success"; } public ObjectgetModel(){ // TODO Auto-generatedmethodstub return null; } public CtypegetCtype(){ return ctype; public void setCtype(Ctypectype){ this.ctype =ctype; } } Editctypesql()方法如下: public Ctype editctypesql(int ct_id) throws IOException{ dbcon=new DBConnection(); con=dbcon.getCon(); Ctypecty=null; Listctylist=new ArrayList(); try { psta=con.prepareStatement(this.getEditCtypesql(ct_id)); psta.setInt(1,ct_id); rs=psta.executeQuery(); while(rs.next()) { cty=new Ctype(); cty.setCt_id(rs.getInt("ct_id")); cty.setCt_name(rs.getString("ct_name")); cty.setCt_sid(rs.getString("ct_sid")); //数据类型Clob转换String类型START// try { oracle.sql.CLOBclob=(oracle.sql.CLOB)rs.getClob("ct_introduction");//数据库中存文本的CLOB型字段名 Stringct_introduction=clob.getSubString((long)1,(int)clob.length());//subString是截取字符串(从1截到length) if(clob==null||ct_introduction==null||ct_introduction==""){ return null; } cty.setCt_introduction(ct_introduction); System.out.println(ct_introduction); }//try catch(Exceptione){ logger.debug("数据类型Clob转换String类型出现异常"); logger.info("数据类型Clob转换String类型出现异常"); e.printStackTrace(); } //数据类型Clob转换String类型END// cty.setCt_image(rs.getString("ct_image")); ctylist.add(cty); } } catch (SQLExceptione){ // TODO Auto-generatedcatchblock e.printStackTrace(); } return cty; } public StringgetEditCtypesql(int ct_id){ this.editCtypesql="select*fromsystem.ctypewherect_id=? "; return editCtypesql; } public void setEditCtypesql(StringeditCtypesql){ this.editCtypesql =editCtypesql; } 注明: 上述方法中涉及到Oracle数据类型Clob转换成String类型问题 在jsp中使用 property value="ctype.ct_id"/> 即可取出ctype中的数据。 13、js“返回上一页” (
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- struts2 工作总结