【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:AlbumAction.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.0/xslt/JavaClass.xsl
package book.example.photoprint.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import book.example.photoprint.exception.DBException;
import book.example.photoprint.form.AlbumForm;
import book.example.photoprint.form.OrderForm;
import book.example.photoprint.po.Album;
import book.example.photoprint.po.User;
import book.example.photoprint.service.AlbumService;
import book.example.photoprint.service.PhotoService;
/**
* MyEclipse Struts Creation date: 12-20-2005
*
* XDoclet definition:
*
* @struts.action path="albumAction" name="albumForm" input="album_add.jsp"
* parameter="method" scope="request"
* @struts.action-forward name="add_success" path="add_success.jsp"
* @struts.action-forward name="error" path="/error.jsp"
*/
public class AlbumAction extends DispatchAction {
// --------------------------------------------------------- Instance
// Variables
// --------------------------------------------------------- Methods
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AlbumForm albumForm = (AlbumForm) form;
Album album = new Album();
if (albumForm.getId() != null && !albumForm.getId().equals("")) {
album.setId(albumForm.getId());
}
album.setName(albumForm.getName());
album.setDescription(albumForm.getDescription());
album.setUserid(albumForm.getUserid());
AlbumService service = new AlbumService();
try {
service.addAlbum(album);
} catch (DBException e) {
e.printStackTrace();
return mapping.findForward("error");
}
return mapping.findForward("add_success");
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AlbumService service = new AlbumService();
try {
List list = service.list();
request.setAttribute("list", list);
} catch (DBException e) {
e.printStackTrace();
return mapping.findForward("error");
}
return mapping.findForward("list");
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String albumid = request.getParameter("id");
AlbumService service = new AlbumService();
try {
service.delete(albumid);
} catch (DBException e) {
e.printStackTrace();
return mapping.findForward("error");
}
return mapping.findForward("delete_success");
}
public ActionForward listByUserId(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AlbumService service = new AlbumService();
User user = (User) request.getSession().getAttribute("user");
String userid = user.getId();
try {
List list = service.listByUserId(userid);
request.setAttribute("list", list);
} catch (DBException e) {
e.printStackTrace();
return mapping.findForward("error");
}
return mapping.findForward("list");
}
public ActionForward modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String albumid = request.getParameter("id");
AlbumForm albumForm = new AlbumForm();
AlbumService service = new AlbumService();
try {
Album album = service.getAlbum(albumid);
albumForm.setId(album.getId());
albumForm.setName(album.getName());
albumForm.setDescription(album.getDescription());
albumForm.setUserid(album.getUserid());
} catch (DBException e) {
e.printStackTrace();
return mapping.findForward("error");
}
request.setAttribute("albumForm", albumForm);
return mapping.findForward("modify");
}
/**
* 查看订单的所有相片
列表 * @param mapping