propertyvalue="ncontent"/>取出即可
使用模型驱动:
查改
新建action查询文章类型:
importjavax.servlet.http.HttpServletRequest;
importorg.apache.struts2.ServletActionContext;
importcom.opensymphony.xwork2.ActionContext;
importcom.opensymphony.xwork2.ActionSupport;
importcom.opensymphony.xwork2.ModelDriven;
importcom.txxw.cms.news.model.Ctype;
importcom.txxw.cms.news.model.CtypeService;
/**
*@authorfejdE-mail:
lzd_niit_java@
*@version创建时间:
May22,20091:
43:
21PM
*功能实现:
文章类型修改内容查询
*/
publicclassCtypeeditActionextendsActionSupportimplementsModelDriven{
privateCtypectype=newCtype();//将封装数据的ctype实现get和set方法
@Override
publicStringexecute()throwsException{
//TODOAuto-generatedmethodstub]
HttpServletRequestrequest=ServletActionContext.getRequest();
intct_id=Integer.parseInt(request.getParameter("ct_id").replace(",",""));//通过选择复选框来实现单个文章类型修改
CtypeServicecs=newCtypeService();
Ctypectype=cs.editctypesql(ct_id);
this.setCtype(ctype);
return"success";
}
publicObjectgetModel(){
//TODOAuto-generatedmethodstub
returnnull;
}
publicCtypegetCtype(){
returnctype;
}
publicvoidsetCtype(Ctypectype){
this.ctype=ctype;
}
}
Editctypesql()方法如下:
publicCtypeeditctypesql(intct_id)throwsIOException{
dbcon=newDBConnection();
con=dbcon.getCon();
Ctypecty=null;
Listctylist=newArrayList();
try{
psta=con.prepareStatement(this.getEditCtypesql(ct_id));
psta.setInt(1,ct_id);
rs=psta.executeQuery();
while(rs.next())
{
cty=newCtype();
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==""){
returnnull;
}
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){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
returncty;
}
publicStringgetEditCtypesql(intct_id){
this.editCtypesql="select*fromsystem.ctypewherect_id=?
";
returneditCtypesql;
}
publicvoidsetEditCtypesql(StringeditCtypesql){
this.editCtypesql=editCtypesql;
}
注明:
上述方法中涉及到Oracle数据类型Clob转换成String类型问题
在jsp中使用
propertyvalue="ctype.ct_id"/>
即可取出ctype中的数据。
10、Struts2+ajax实现批量删除,批量更新操作
全选:
checkAll()
不选:
checkAllNo()
反选:
swichAll()
批量删除:
deletenews()
批量更新:
display1news()
functioncheckAll(){
varobj=document.getElementsByName("nid");
for(i=0;iobj[i].checked=true;
}
}
functioncheckAllNo(){
varobj=document.getElementsByName("nid");
for(i=0;iobj[i].checked=false;
}
}
functionswitchAll(){
varobj=document.getElementsByName("nid");
for(i=0;iobj[i].checked=!
obj[i].checked;
}
}
functionvals(input1,input2)
{
vartemp="";
varobjForm=document.forms[input1];
varobjLen=objForm.length;
for(variCount=0;iCount{
if(objForm.elements[iCount].type=="checkbox")
{
if(objForm.elements[iCount].checked==true&&objForm.elements[iCount].nid!
="allSelected"&&objForm.elements[iCount].nid!
="allConcled")
{
temp=temp+objForm.elements[iCount].value+",";
}
//objForm.elements[iCount].checked=true;
}
}
returntemp;
}
functiondeletenews(){
varnid=vals('form1','this')
if(nid==""){
alert('你没有选中内容');
returnfalse;
}else{
if(confirm('你确定要删除选中的内容吗'+'?
'+nid)){
varurl="delete.action?
nid="+nid;
window.location.href=url;
}
}
}
functiondisplay1news(){
varnid=vals('form1','this')
if(nid==""){
alert('你没有选中内容');
returnfalse;
}else{
if(confirm('你确定要显示选中的内容吗'+'?
'+nid)){
varurl="display1news.action?
nid="+nid;
window.location.href=url;
}
}
}
11、控制Struts2form>提交表单样式
--form提交表单样式设置Start-->
--
form{margin:
0px;display:
inline;}
-->
--控制form表单样式-->
functionsub()
{
document.form.submit();
}
--form提交表单样式设置End-->
12、ajax前台验证(一部分)
functioncheck()
{
if(document.getElementById("ct_name").value==""){
alert("请输入栏目名称!
");
returnfalse;
}
document.form.submit();
}
functioncheck()
{
if(document.getElementById("ntitle").value==""){
alert("请输入文章标题!
");
returnfalse;
}
if(document.getElementById("nprovider").value==""){
alert("请输入供稿人!
");
returnfalse;
}
if(document.getElementById("ntelephone").value==""){
alert("请输入联系电话!
");
returnfalse;
}
varpartten1=/^1[3,5]\d{9}$/;
varpartten2=/^0(([1,2]\d)|([3-9]\d{2}))\d{8}$/;
if(partten1.test(document.getElementById("ntelephone").value)==false&&partten2.test(document.getElementById("ntelephone").value)==false)
{
alert("请检查您输入的联系电话格式");
returnfalse;
}
if(document.getElementById("email").value==""){
alert("请输入Email!
");
returnfalse;
}
varzz=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if(zz.test(document.getElementById("email").value)==false)
{
alert("请输入正确格式的Email.");
returnfalse;
}
document.form.submit();
}
formaction="updatectype"name="form"method="post"theme="simple">
textfieldname="ctype.ct_name"id="ct_name"size="30">
textfield>
form>
functioncheck()
{
if(document.getElementById("nt").value=="")
{
alert("请输入查询关键字");
returnfalse;
}
document.getElementById("form2").submit();
}
按标题:
hiddenna