Struts2 开发总结7—13

Struts2开发总结

(注:Struts2版本:Struts2.1.6,数据库:Oracle9i

7、  FCK网页编辑器的使用:

 

<%@ taglib uri="/FCKeditor" prefix="FCK"%>

body体中引用:

<FCK:editor id="ncontent" width="90%" height="320"

fontNames="宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier

New;Tahoma;Times New Roman;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">

</FCK:editor>

 

3、  Struts2下拉菜单的使用

<s:select name="ct_sid" list="ctypesonlist" listKey="ct_id"

listValue="ct_name" theme="simple" headerKey="0"

headerValue="一级栏目">

</s:select>

 

<s:select name="ninvalidate" list="#{1:'',2:''}"

listKey="key" listValue="value" headerKey="0"></s:select>

属性注解:name是给Struts2<s:select>标签取名字,这个也是提交到action并保存到对应的数据库中的字段名所必须得参数;list是下拉选项数值;listKey是选项列表所对应的idlistValue是选项列表每个字段的名称;theme是自定义下拉框格式,headerkey是首选项的主键idheaderValue是首选项的字段名

 

4、  Struts2.1.6使用日期控件:

需要导入包:struts2-dojo-plugin-2.1.6.jar

<%@ taglib uri="/struts-dojo-tags" prefix="sx"%>

head体中加入:<sx:head />

body体中引用:

<sx:datetimepicker name="ninvalidate_time" type="date"

displayFormat="yyyy/MM/dd" value="%{'today'}"></sx:datetimepicker>

属性注解:name是给<sx:detetimepicker>标签取名,typedate日期类型,displayFormat格式化显示日期,value是获取时间值,value="%{'today'}"是获取当前系统时间

 

5、  Struts2隐藏域标签:

<s:hidden name="auditing" value="1"></s:hidden>

 

11Struts2form提交表单格式

<s:form action="login" method="post" theme="simple" validate="true">

</s:form>

form中加入theme="simple"属性,就不会受Struts2<s:form>定义格式的影响

 

12、使用属性驱动取值

action中将要输出的属性生成getset方法,并将返回值定义为返回对象,如:

private String  ntitle;//标题

private String ncontent;//内容

private String ntime;//时间

private String username;//发布人

 

News news=ns.queryNnewsdetailsql2(nid);//返回一个对象

 

public String getNtitle() {

       return ntitle;

    }

    public void setNtitle(String ntitle) {

       this.ntitle = ntitle;

    }

    public String getNcontent() {

       return ncontent;

    }

    public void setNcontent(String ncontent) {

       this.ncontent = ncontent;

    }

    public String getNtime() {

       return ntime;

    }

    public void setNtime(String ntime) {

       this.ntime = ntime;

    }

    public String getUsername() {

       return username;

    }

    public void setUsername(String username) {

       this.username = username;

    }

action直接跳转到要显示这些属性详细内容的页面

jsp中直接使用标签<s: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:[email protected]

 * @version 创建时间:May 22, 2009 1:43:21 PM

 * 功能实现:文章类型修改内容查询

 */

public class CtypeeditAction extends ActionSupport implements ModelDriven {

 

    private Ctype ctype=new Ctype();//将封装数据的ctype实现getset方法

    @Override

    public String execute() throws Exception {

       // TODO Auto-generated method stub]

       HttpServletRequest request=ServletActionContext.getRequest();

       int ct_id=Integer.parseInt(request.getParameter("ct_id").replace(",", ""));//通过选择复选框来实现单个文章类型修改

       CtypeService cs=new CtypeService();

        Ctype ctype=cs.editctypesql(ct_id);

       this.setCtype(ctype);

       return "success";

    }

 

    public Object getModel() {

       // TODO Auto-generated method stub

       return null;

    }

 

    public Ctype getCtype() {

       return ctype;

 

如果文章中有瑕疵,欢迎各位提出并修改;技术王国,共同进步。O(_)O~

你可能感兴趣的:(jsp,cms,fckeditor,Flash,dojo)