photocontrol.java

来自「java带进度条上传尽量不要让站长把时间都花费在为您修正说明上」· Java 代码 · 共 281 行

JAVA
281
字号
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.jmwl.control;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.actions.DispatchAction;

import com.jmwl.biz.PhotoService;
import com.jmwl.biz.PictureService;
import com.jmwl.biz.UsersService;
import com.jmwl.common.BlogException;
import com.jmwl.common.DateTime;
import com.jmwl.dto.PhotoDTO;
import com.jmwl.form.PhotoForm;
import com.jmwl.vo.PictureVO;

/** 
 * MyEclipse Struts
 * Creation date: 08-22-2008
 * 
 * XDoclet definition:
 * @struts.action path="/photo" name="photoForm" input="/createPhoto.jsp" scope="request" validate="true"
 */
public class PhotoControl extends DispatchAction {
	/*
	 * Generated Methods
	 */

	/** 
	 * 创建相册
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws BlogException 
	 */
	public ActionForward createPhoto(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		PhotoForm photoForm = (PhotoForm) form;// TODO Auto-generated method stub
		String photo_name="";
		String photo_password="";
		String photo_description="";
		try
		{
			photo_name=photoForm.getPhoto_name().trim();
			photo_password=photoForm.getPhoto_password().trim();
			photo_description=photoForm.getPhoto_description().trim();
		}
		catch(NullPointerException e)
		{
		}
		String create_time=new DateTime().getCurDate();
		int userid= ((Integer) request.getSession().getAttribute("userid")).intValue();
		int visit_count=0;
		int photo_state=1;
		PhotoDTO pdto=new PhotoDTO();
		pdto.setCreate_time(create_time);
		pdto.setPhoto_name(photo_name);
		pdto.setPhoto_description(photo_description);
		pdto.setPhoto_password(photo_password);
		pdto.setPhoto_state(photo_state);
		pdto.setUserid(userid);
		pdto.setVisit_count(visit_count);
		pdto.setUsername(""+request.getSession().getAttribute("nickname"));
		PhotoService psce=new PhotoService();
		if(psce.newPhoto(pdto))
		{
			request.setAttribute("succ", "创建相册成功!");
			return mapping.findForward("success");
		}
		else	
			return mapping.findForward("error");
	}
	
	/**
	 * 显示个人相册
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws BlogException
	 */
	public ActionForward showOnePhotos(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
	
		
		int pageNow=1;
		int pageCount=0;
		int rowCount=5;
		int allCount=0;
		int userid=0;
		try
		{
			userid= (Integer) request.getSession().getAttribute("userid");
		}
		catch(NumberFormatException e)
		{
			userid=((Integer) request.getSession().getAttribute("bid")).intValue();
		}
		catch(NullPointerException e)
		{
			userid=((Integer) request.getSession().getAttribute("bid")).intValue();
		}
		try
		{
			pageNow=Integer.parseInt(request.getParameter("pageNow"));
		}
		catch(NumberFormatException e)
		{
			pageNow=1;
		}
		
		ActionErrors errors=new ActionErrors();
		
		PhotoService psce=new PhotoService();
		allCount=psce.getAllCount(userid);
		
		if(allCount%rowCount==0)
		{
			pageCount=allCount/rowCount;
		}
		else
		{
			pageCount=allCount/rowCount+1;
		}
		if(pageNow>pageCount)
		{
			pageNow=pageCount;
		}
		if(pageNow<1)
		{
			pageNow=1;
		}
		request.setAttribute("userid", userid);
		request.setAttribute("allCount", allCount);
		request.setAttribute("pageNow",String.valueOf(pageNow));
		request.setAttribute("pageCount",String.valueOf(pageCount));
		List list=psce.getOnePhotos(pageNow, rowCount, userid);
		request.setAttribute("list", list);
		return mapping.findForward("showPhotos");	
	}
	
	public ActionForward delPhoto(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		
		int photo_id=Integer.parseInt(request.getParameter("photo_id"));
		PhotoDTO pdto=new PhotoDTO();
		pdto.setId(photo_id);
		PictureService ptsce=new PictureService();
		PhotoService psce=new PhotoService();
		List list=ptsce.getOneUserPictures(pdto);
		String realpath=this.servlet.getServletContext().getRealPath("");
		for (int i = 0; i < list.size(); i++) 
		{
			PictureVO ptvo=(PictureVO)list.get(i);
			String path=realpath+"\\"+ptvo.getPicture_uri();
			File file=new File(path);
			file.delete();
		}
		ptsce.delOnePhotoPictures(pdto);
		if(psce.delPhoto(pdto))
		{
			request.setAttribute("succ", "删除相册成功!");
			return mapping.findForward("success");
		}
		else
		{
			return mapping.findForward("error");
		}
		
	}
	
	public ActionForward editPhoto(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		String flag=request.getParameter("flag");
		PhotoDTO pdto=new PhotoDTO();
		PhotoService psce=new PhotoService();
		int id=Integer.parseInt(request.getParameter("id"));
		if(flag.equals("1"))
		{
			String password = request.getParameter("password1");
			pdto.setPhoto_password(password);
		}
		if(flag.equals("2"))
		{
			String oldpsw = request.getParameter("password3");
			String oldpassword = psce.checkPassword(id);
			String newPassword = request.getParameter("password4");
			if(oldpassword.equals(oldpsw))
			{
				pdto.setPhoto_password(newPassword);
			}
			else if("".equals(oldpsw))
			{
				pdto.setPhoto_password(oldpassword);
			}
			else
			{
				ActionErrors errors = new ActionErrors();
				ActionMessage message = new ActionMessage("editphoto.oldpassword");
				errors.add("passworderr",message);
				this.addErrors(request, errors);
				System.out.println(444444);
				return new ActionForward("/pictures/editphoto.jsp");
			}
			
		}
		String photo_name=request.getParameter("photo_name");
		String photo_description=request.getParameter("photo_description");
		pdto.setPhoto_name(photo_name);
		pdto.setPhoto_description(photo_description);
		pdto.setId(id);
		boolean b=psce.editPhoto(pdto);
		if(b)
		{
			request.setAttribute("succ", "修改相册成功!");
			return mapping.findForward("success");
		}
		else
			return mapping.findForward("error");
	}
	
	public ActionForward showPhotoPassword(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException, ServletException, IOException {
			String answer = request.getParameter("answer");
			PhotoService pse = new PhotoService();
			int photo_id = Integer.parseInt(request.getParameter("photo_id"));
			String st = pse.checkPassword(photo_id);
			if(st.equals(answer))
			{
				response.sendRedirect("/javablog/showpicture.do?method=showPictures&photo_id="+photo_id);
				return null;
			}else{
				request.setAttribute("err", "相册密码错误,请返回!");
				return mapping.findForward("error");
			}
			
	}
	
	public ActionForward getHighPhoto(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException, ServletException, IOException {
			PhotoService ps = new PhotoService();
			UsersService us = new UsersService();
			List list = ps.getHighPhoto();
			List list2 = ps.getHighPhoto2();
			request.setAttribute("list", list);
			request.setAttribute("list2", list2);
		return mapping.findForward("photoindex");
	}
	
	
	
	
	
	
	
	
	
	
	
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?