日期:2014-05-17  浏览次数:20711 次

头大的问题?高手请进……

public class SubItemAction extends ActionSupport{
private int id ;
private SubItem subItem ;
private String manager ;
private SubItemManager subItemManager ;
private String subName ;
private Item item ;
private String subDescription ; 

private List<Item> items ;
//版主
private User user ;


//添加子栏目
public String addSubItem(){
user.setName(manager);  

//查找父栏目
item = itemManager.find(id);
subItem.setItem(item);
subItem.setManager(user);
subItem.setSubItemName(subName);
subItem.setSubItemDescription(subDescription);

//添加子栏目
boolean bool = subItemManager.add(subItem);
if(bool){
return "success";
}else{
return "fail" ;
}
}
//添加子栏目页面
public String addSubItemInput(){
items = itemManager.browse();
return "input";
}

public String getSubName() {
return subName;
}

public void setSubName(String subName) {
this.subName = subName;
}

public String getSubDescription() {
return subDescription;
}

public void setSubDescription(String subDescription) {
this.subDescription = subDescription;
}
}

struts.xml配置:
 <action name="subItem" class ="com.bbs.action.SubItemAction" method="{1}">
  <result name="input">  
  /jsp/admin/subItem-input.jsp
  </result>
  <result name="success">  
  /jsp/admin/subItem-success.jsp
  </result>
  <result name="fail">  
  /jsp/admin/subItem-fail.jsp
  </result>
  </action>

public class SubItemManager {
//增加子栏目
public boolean add(SubItem subItem){
String subItemName = subItem.getSubItemName();
//查找子栏目
SubItem sub = subItemDAO.find(subItemName);
if(sub == null){
//查找用记
User user = userDAO.exist(subItem.getManager().getName());
if(user != null){
//设为版主
subItem.setManager(user);
//添加子栏目
subItemDAO.add(subItem);
return true ;
}
return false ;
}else{
return false ;
}
}
}

public classs SubItemDAO {
private HibernateTemplate hibernateTemplate ;

//增加子栏目
public void add(SubItem subItem){
hibernateTemplate.save(subItem);
}

//以名字方式查找子栏目
public SubItem find(String subItemName){
List<SubItem>items = hibernateTemplate.find("from SubItem where subItemName=?",subItemName);
if(items.size() > 0){
return items.get(0);
}else {
return null ;
}
}
}

subItem-input.jsp页面代码:
<%@ page language = "java" import = "java.util.*" pageEncoding ="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form action="subItem-addSubItem">
<table width="468" border="1" align="center">
<tr><