📄 contentsaction.java
字号:
package com.xaccp.aj3q8073.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.xaccp.aj3q8073.controller.Action;
import com.xaccp.aj3q8073.controller.ActionForward;
import com.xaccp.aj3q8073.dao.ContentsManagerDao;
import com.xaccp.aj3q8073.vo.BookShelfVo;
/**
* 栏目管理的action
* 通过反射找到的类
* 之所以去实现接口是因为它规范了我们
* 的输入和输出
* @author Administrator
*
*/
public class ContentsAction implements Action {
ContentsManagerDao dao=new ContentsManagerDao();
/**
* 查找一级目录
*/
public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
List list= dao.findOneBookshelf();
request.setAttribute("oneBookshelf", list);
return new ActionForward("/background/saloonTypeModify.jsp");
}
/**
* 查找二级目录的同时也要显示一级目录
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward findTwoBookshelf(HttpServletRequest request, HttpServletResponse response) throws Exception {
// String name= request.getParameter("shelfName");
// //对汉字进行解码
// name=java.net.URLDecoder.decode(name,"UTF-8");
// name=new String(name.getBytes("iso-8859-1"),"UTF-8");
//获取一级书架id
String shelfId=request.getParameter("shelfId");
// if (shelfId==null)
// {
// shelfId="0";
// }
//根据货架Id查询货架Name
BookShelfVo bv= dao.findShelfName(Integer.parseInt(shelfId));
BookShelfVo shelfVo=new BookShelfVo();
shelfVo.setShelfId(Integer.parseInt(shelfId));
shelfVo.setShelfName(bv.getShelfName());
request.setAttribute("shelf", shelfVo);
List listOne= dao.findOneBookshelf();
request.setAttribute("oneBookshelf", listOne);
List listTwo= dao.findTwoBookshelfName(Integer.parseInt(shelfId));
request.setAttribute("twoBookshelf", listTwo);
return new ActionForward("/background/saloonTypeModify.jsp");
}
/**
*栏目管理
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward saveContectAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
String shelfId= request.getParameter("shelfId");
String twoId=request.getParameter("twoId");//拿到二级目录id
String file=request.getParameter("file");
String type=request.getParameter("type");
String contentName=request.getParameter("contentName");
List listName= dao.findContentName(contentName);
if(listName.size()>0){
return new ActionForward("/background/info.jsp",true);
}
BookShelfVo vo=new BookShelfVo();
vo.setParentShelfId(Integer.parseInt(shelfId));
vo.setShelfName(contentName);
if(type.equals("增加子栏目")){
dao.saveContent(vo);
response.sendRedirect(request.getContextPath()+"/twoContent.do?shelfId="+shelfId);
}else if(type.equals("增加兄弟栏目")){
if(twoId==""){
dao.saveBrotherContent(contentName);
return new ActionForward("/contents.do",true);
}else{
dao.saveContent(vo);
response.sendRedirect(request.getContextPath()+"/twoContent.do?shelfId="+shelfId);
}
}else if(type.equals("修改栏目")){
//TODO...图书表中的名称也要修改
if(twoId==""){
dao.editContent(contentName, Integer.parseInt(shelfId));
return new ActionForward("/contents.do",true);
}else{
dao.editContent(contentName, Integer.parseInt(twoId));
response.sendRedirect(request.getContextPath()+"/twoContent.do?shelfId="+shelfId);
}
}else if(type.equals("删除栏目")){
if(twoId==""){
List list= dao.findTwoBookshelfName(Integer.parseInt(shelfId));
if(list.size()>0){
return new ActionForward("/background/clew.jsp",true);
}else{
dao.removeOneContentByShelfId(Integer.parseInt(shelfId));
return new ActionForward("/contents.do",true);
}
}else{
List list= dao.findBook(Integer.parseInt(twoId));
if(list.size()>0){
return new ActionForward("/background/clew.jsp",true);
// response.sendRedirect(request.getContextPath()+"/twoContent.do?shelfId="+shelfId);
}else{
dao.removeOneContentByShelfId(Integer.parseInt(twoId));
response.sendRedirect(request.getContextPath()+"/twoContent.do?shelfId="+shelfId);
}
}
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -