showlistaction.java

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

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.mail.internet.NewsAddress;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

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 com.jmwl.biz.NotesSerivce;
import com.jmwl.biz.NotesTypeService;
import com.jmwl.biz.ReplyService;
import com.jmwl.common.BlogException;
import com.jmwl.form.WritenoteForm;
import com.jmwl.vo.NoteTypeVO;
import com.jmwl.vo.NoteVO;
import com.jmwl.vo.NotelistVO;
import com.jmwl.vo.Re_UserVO;
import com.jmwl.vo.ReplyVO;
import com.jmwl.dto.*;

/** 
 * MyEclipse Struts
 * Creation date: 08-25-2008
 * 
 * XDoclet definition:
 * @struts.action
 */
public class ShowlistAction extends DispatchAction {

//	public ActionForward execute(ActionMapping mapping, ActionForm form,
//			HttpServletRequest request, HttpServletResponse response) {
//		// TODO Auto-generated method stub
//		return null;
//	}
/**
 * 显示一个初级的日志列表
 */	
	public ActionForward noteinfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		NotesSerivce db=new NotesSerivce();
		HttpSession session=request.getSession();
//		String u_id=(String)session.getAttribute("bid");
//		int id=Integer.parseInt(u_id);
		int id=(Integer)session.getAttribute("bid");
		System.out.println("id-----------"+id);
		
		String m=(String)request.getParameter("currpage");
		int page=db.getcountpage(id);
		int currpage=0;
		if(m==null)
		{
			currpage=1;
		}
		else
		{
			currpage=Integer.parseInt(m);
		}
		if(currpage<1)
		{
			currpage=1;
		}
		if(currpage>page)
		{
			currpage=page;
		}
		request.setAttribute("page", page);
		request.setAttribute("currpage", currpage);
		System.out.println("当前页------------"+currpage);
		System.out.println("总页数--------------"+page);
		List<NoteVO> list1=new ArrayList();
		list1=db.get_all_note(id,currpage);
		request.setAttribute("list_note", list1);//保存所有日志列表
		
		List<NotelistVO> list2=new ArrayList();
		list2=db.get_list();
		request.setAttribute("list_type", list2);//保存日志类型列表
		Map map=new HashMap();
		for(NotelistVO info:list2)
		{
			int n=db.get_note_sl(id, info.getId());
			map.put(info.getId(), n);
		}
		request.setAttribute("map", map);//保存每种日志的数量
		
		int count=db.getn(id);
		request.setAttribute("count", count);//保存日志的数量
		
		Re_UserVO userinfo=new Re_UserVO();
		ReplyService re=new ReplyService();
		userinfo=re.get_user(id);
		request.setAttribute("userinfo", userinfo);//保存用户信息
		

		
		return mapping.findForward("show");
	}
	/**
	 * 显示一个指定类型的日志列表
	 * @throws BlogException 
	 */
	public ActionForward note_type_info(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		NotesSerivce db=new NotesSerivce();
		HttpSession session=request.getSession();
//		String u_id=(String)session.getAttribute("bid");
//		int id=Integer.parseInt(u_id);
		
		int id=(Integer)session.getAttribute("bid");
		
		String type_id=(String)request.getParameter("notetype");
		int tid=Integer.parseInt(type_id);
		
		String m=request.getParameter("currpage");
		int currpage=0;
		int m1=db.getonepage(id, tid);
		if(m==null)
		{
			currpage=1;
		}
		else
		{
			currpage=Integer.parseInt(m);
		}
		if(currpage<1)
		{
			currpage=1;
		}
		if(currpage>m1)
		{
			currpage=m1;
		}
		
		List<NoteVO> list1=db.get_type_note(tid, id,currpage);
		request.setAttribute("list_note", list1);//保存指定类型日志列表
		request.setAttribute("m1", m1);
		request.setAttribute("currpage", currpage);
		request.setAttribute("notetype", tid);
		
		List<NotelistVO> list2=new ArrayList();
		list2=db.get_list();
		request.setAttribute("list_type", list2);//保存日志类型列表
		Map map=new HashMap();
		for(NotelistVO info:list2)
		{
			int n=db.get_note_sl(id, info.getId());
			map.put(info.getId(), n);
		}
		request.setAttribute("map", map);//保存每种日志的数量
		
		int count=db.getn(id);
		request.setAttribute("count", count);//保存日志的数量
		
		Re_UserVO userinfo=new Re_UserVO();
		ReplyService re=new ReplyService();
		userinfo=re.get_user(id);
		request.setAttribute("userinfo", userinfo);//保存用户信息
		
		
	//	return mapping.findForward("show");
		System.out.println("uid-----"+id);
		System.out.println("tid-----"+tid);
		System.out.println("currpage------"+currpage);
		System.out.println("m1--------"+m1);
		System.out.println("下面的日志列表");
		for(NoteVO info:list1)
		{
			System.out.println(info.getTitle());
		}
		System.out.println("下面的是日志类型的列表");
		for(NotelistVO info1:list2)
		{
			System.out.println(info1.getType_name());
		}
		System.out.println("下面的是用户信息");
		System.out.println(userinfo.getNickName());
		return mapping.findForward("show");
	}
	
	
	/**
	 * 删除一篇日志
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws BlogException
	 */
	public ActionForward deletenote(ActionMapping mapping, ActionForm form,
	HttpServletRequest request, HttpServletResponse response) throws BlogException {
		NotesSerivce db=new NotesSerivce();
		String note_id=request.getParameter("note_id");
		int noteid=Integer.parseInt(note_id);
		boolean b=db.delete_note(noteid);
		
		ReplyService re=new ReplyService();
		boolean n=re.delete_reply(noteid);
		if(b)
			{request.setAttribute("b", "1");
			return mapping.findForward("dis");}
		else
		{request.setAttribute("b", "2");
		return mapping.findForward("dis");}
	}
	/**
	 * 编辑一篇日志的连接
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws BlogException
	 */
	public ActionForward updatenote(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		HttpSession session=request.getSession();
//		String bid=(String)session.getAttribute("bid");
		
		
		
		String note_id=request.getParameter("note_id");
		int noteid=Integer.parseInt(note_id);
		NotesSerivce db=new NotesSerivce();
		List<NotelistVO> list=new ArrayList();
		list=db.get_list();
		request.setAttribute("list_type", list);//保存日志类型列表
//		for(NotelistVO info:list)
//		{
//			System.out.println(info.getType_name());
//		}
		
		NoteVO note=db.getnote(noteid);
		request.setAttribute("note", note);//保存一篇日志的全部信息
		
		return mapping.findForward("update");
			}
	/**
	 * 写日志的链接
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws BlogException
	 */
	public ActionForward writenote(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		NotesSerivce db=new NotesSerivce();
		List<NotelistVO> list=new ArrayList();
		list=db.get_list();
		request.setAttribute("list_type", list);//保存日志类型列表		
		return mapping.findForward("write");
			}
	
	public ActionForward addNote(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		WritenoteForm writenoteForm = (WritenoteForm) form;
//		String title=writenoteForm.getTitle();
//		String notetype=writenoteForm.getNote_type();
//		String content=writenoteForm.getContent();
//		int note_type=Integer.parseInt(notetype);
//		HttpSession session=request.getSession();
//		String id=(String) session.getAttribute("uid");
//		int user_id=Integer.parseInt(id);
//		
//		NoteDTO info=new NoteDTO();
//		info.setUser_id(user_id);
//		info.setNote_type_id(note_type);
//		info.setTitle(title);
//		info.setContent(content);
//
//		NotesSerivce db=new NotesSerivce();
//		boolean b=db.addnote(info);
		HttpSession session=request.getSession();

		
		int uid=(Integer)session.getAttribute("uid");
		
		String title=writenoteForm.getTitle();
		String content=writenoteForm.getContent();
		String note_type=writenoteForm.getNote_type();
		int notetype=Integer.parseInt(note_type);
		NoteDTO info=new NoteDTO();
		info.setUser_id(uid);
		info.setTitle(title);
		info.setContent(content);
		info.setNote_type_id(notetype);
		NotesSerivce db=new NotesSerivce();
		boolean b=db.addnote(info);
		boolean a=db.add_note_jf(info.getUser_id());
		if(b)
		{
			System.out.println("添加成功");
			request.setAttribute("b", "true");
		}
		else
		{
			System.out.println("添加失败");
			request.setAttribute("b", "false");
		}
		return mapping.findForward("dis");
	}
	/**
	 * 实现修改日志
	 */
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws BlogException {
		WritenoteForm writenoteForm = (WritenoteForm) form;
		String id=writenoteForm.getId();
		int note_id=Integer.parseInt(id);
		String title=writenoteForm.getTitle();
		String notetype=writenoteForm.getNote_type();
		int note_type=Integer.parseInt(notetype);
		String content=writenoteForm.getContent();
		NotesSerivce db=new NotesSerivce();
		Note_updateDTO info=new Note_updateDTO();
		info.setId(note_id);
		info.setTitle(title);
		info.setNtoe_type_id(note_type);
		info.setContent(content);
		boolean b=db.update_note(info);
		
		if(b)
		{request.setAttribute("b", "1");
		return mapping.findForward("dis");}
		else
		{request.setAttribute("b", "2");
		return mapping.findForward("dis");}
			}
	/**
	 * 查看一篇日志
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws BlogException
	 */
	public ActionForward seenote(ActionMapping mapping, ActionForm form,
	HttpServletRequest request, HttpServletResponse response) throws BlogException {
		String id=request.getParameter("note_id");
		int note_id=Integer.parseInt(id);
		NotesSerivce db=new NotesSerivce();
		NoteVO info=new NoteVO();
		info=db.getnote(note_id);
		boolean b=db.see_cs(note_id);
		request.setAttribute("info", info);
		

		
		List<ReplyVO> list=new ArrayList();
		ReplyService re=new ReplyService();
		
		String n=request.getParameter("currpage");
		int currpage=0;
		int page=re.gethfpage(note_id);
		System.out.println(note_id+"page-----"+page);
		if(n==null)
		{
			currpage=1;
		}
		else
		{
			currpage=Integer.parseInt(n);
		}
		if(currpage<1)
		{
			currpage=1;
		}
		if(currpage>page)
		{
			currpage=page;
		}
		
		list=re.get_replyinfo(note_id,currpage);
		request.setAttribute("re", list);
		request.setAttribute("logid", note_id);
		request.setAttribute("currpage", currpage);
		request.setAttribute("page", page);
		return mapping.findForward("see");
	}
	
	
	
	
	
}

⌨️ 快捷键说明

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