?? articleservlet.java
字號:
if(info==null||info.equals("")){
mark=false;
messages+="<li>請輸入 <b>文章描述!</b></li>";
}
if(content==null||content.equals("")){
mark=false;
messages+="<li>請輸入 <b>文章內容!</b></li>";
}
if(mark){
title=MyTools.toChinese(title);
content=MyTools.toChinese(content);
if(title.length()>20){
mark=false;
messages+="<li><b>文章標題</b> 最多允許輸入20個字符!</li>";
}
if(content.length()>4000){
mark=false;
messages+="<li><b>文章內容</b> 最多允許輸入4000個字符!</li>";
}
}
request.setAttribute("messages",messages);
return mark;
}
/**
* @功能 后臺-增加文章
*/
public void addArticle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String messages = "";
String href="";
String forward="";
boolean flag=validateArticle(request,response);
if(flag){
ArticleBean articleBean = new ArticleBean();
articleBean.setTypeId(MyTools.strToint(request.getParameter("typeId")));
articleBean.setTitle(MyTools.toChinese(request.getParameter("title")));
articleBean.setContent(MyTools.changeHTML(MyTools.toChinese(request.getParameter("content"))));
articleBean.setSdTime(MyTools.changeTime(new Date()));
articleBean.setCreate(MyTools.toChinese(request.getParameter("create")));
articleBean.setInfo(MyTools.toChinese(request.getParameter("info")));
articleBean.setCount(0);
ArticleDao articleDao = new ArticleDao();
boolean mark=articleDao.operationArticle("add", articleBean);
if(mark) {
href="<a href='admin/article/ArticleAdd.jsp'>[繼續發表]</a>";
forward="/admin/success.jsp";
}
else{
messages="<li>發表文章失??!</li>";
href="<a href='javascript:window.history.go(-1)'>[返回]</a>";
forward="/admin/error.jsp";
}
request.setAttribute("messages",messages);
request.setAttribute("href",href);
}
else{
href="<a href='javascript:window.history.go(-1)'>[返回]</a>";
forward="/admin/error.jsp";
request.setAttribute("href",href);
}
RequestDispatcher rd = request.getRequestDispatcher(forward);
rd.forward(request, response);
}
/**
* @功能 實現后臺文章管理中的文章瀏覽功能
*/
public void adminSelectList(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
ArticleDao articleDao = new ArticleDao();
String strId=request.getParameter("typeId");
if(strId==null||strId.equals(""))
strId="-1";
int typeId=Integer.parseInt(strId);
session.setAttribute("showTypeId",typeId);
List articleList=articleDao.queryArticle(typeId,"all");
request.setAttribute("articleList",articleList);
RequestDispatcher rd=request.getRequestDispatcher("/admin/article/ArticleList.jsp");
rd.forward(request,response);
}
public void adminSelectSingle(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
int id=MyTools.strToint(request.getParameter("id"));
ArticleDao articleDao = new ArticleDao();
ArticleBean articleBean=articleDao.queryArticleSingle(id); //查詢指定文章的詳細內容
request.setAttribute("articleSingle",articleBean);
RequestDispatcher rd=request.getRequestDispatcher("/admin/article/ArticleSingle.jsp");
rd.forward(request,response);
}
/**
* @功能 從數據表中獲取某類別下的所有文章
*/
public void selectArticle(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
ArticleDao articleDao = new ArticleDao();
String strId=request.getParameter("typeId");
if(strId==null||strId.equals(""))
strId="-1";
int typeId=Integer.parseInt(strId);
List articleList=articleDao.queryArticle(typeId,"all");
request.setAttribute("articleList",articleList);
RequestDispatcher rd=request.getRequestDispatcher("/front/article/ArticleList.jsp");
rd.forward(request,response);
}
public boolean validateType(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
boolean mark=true;
String messages="";
String typeName=request.getParameter("typeName");
String typeInfo=request.getParameter("typeInfo");
if(typeName==null||typeName.equals("")){
mark=false;
messages+="<li>請輸入 <b>類別名稱!</b></li>";
}
if(typeInfo==null||typeInfo.equals("")){
mark=false;
messages+="<li>請輸入 <b>類別介紹!</b></li>";
}
request.setAttribute("messages",messages);
return mark;
}
/**
* @功能 后臺-增加文章類別
*/
public void addArticleType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String messages = "";
String href="";
String forward="";
boolean flag=validateType(request,response);
if(flag){
ArticleTypeBean typeBean = new ArticleTypeBean();
typeBean.setTypeName(MyTools.toChinese(request.getParameter("typeName")));
typeBean.setTypeInfo(MyTools.toChinese(request.getParameter("typeInfo")));
ArticleTypeDao articleTypeDao = new ArticleTypeDao();
boolean mark=articleTypeDao.operationArticleType("add", typeBean);
if(mark) {
messages+="<li>添加文章類別成功!</li>";
href="<a href='admin/article/ArticleTypeAdd.jsp'>[繼續添加文章類別]</a>";
forward="/admin/success.jsp";
}
else {
messages+="<li>添加文章類別失??!</li>";
href="<a href='javascript:window.history.go(-1)'>[返回]</a>";
forward="/admin/error.jsp";
}
request.setAttribute("messages",messages);
request.setAttribute("href",href);
}
else{
href="<a href='javascript:window.history.go(-1)'>[返回]</a>";
forward="/admin/error.jsp";
request.setAttribute("href",href);
}
RequestDispatcher rd=request.getRequestDispatcher(forward);
rd.forward(request,response);
}
public void selectArticleType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ArticleTypeDao typeDao=new ArticleTypeDao();
List typelist=typeDao.queryTypeList();
request.setAttribute("typelist",typelist);
RequestDispatcher rd=request.getRequestDispatcher("/admin/article/ArticleTypeList.jsp");
rd.forward(request,response);
}
/**
* @功能 后臺-修改文章類別
*/
public void modifyArticleType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher rd=null;
ArticleTypeBean typeBean=null;
ArticleTypeDao typeDao=new ArticleTypeDao();
String type=request.getParameter("type");
if(type==null)
type="";
if(!type.equals("doModify")){
int typeId=MyTools.strToint(request.getParameter("typeId"));
typeBean=typeDao.queryTypeSingle(typeId);
request.setAttribute("typeSingle",typeBean);
rd=request.getRequestDispatcher("/admin/article/ArticleTypeModify.jsp");
rd.forward(request,response);
}
else{
String messages="";
String href="";
String forward="";
boolean flag=validateType(request,response);
if(flag){
typeBean = new ArticleTypeBean();
typeBean.setId(MyTools.strToint(request.getParameter("typeId")));
typeBean.setTypeName(MyTools.toChinese(request.getParameter("typeName")));
typeBean.setTypeInfo(MyTools.toChinese(request.getParameter("typeInfo")));
boolean mark=typeDao.operationArticleType("modify",typeBean);
if (mark) {
messages="<li>修改類別成功!</li>";
href="<a href='ArticleServlet?action=typeSelect'>[繼續修改其他類別]</a>";
forward="/admin/success.jsp";
} else {
messages="<li>修改失??!</li>";
href="<a href='javascript:window.history.go(-1)>[返回]</a>";
forward="/admin/error.jsp";
}
request.setAttribute("messages",messages);
request.setAttribute("href",href);
}
else{
href="<a href='javascript:window.history.go(-1)>[返回]</a>";
forward="/admin/error.jsp";
request.setAttribute("href",href);
}
rd=request.getRequestDispatcher(forward);
rd.forward(request,response);
}
}
/**
* @功能 后臺-刪除文章類別
*/
public void deleteArticleType(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
ArticleTypeDao typeDao = new ArticleTypeDao();
ArticleTypeBean typeBean = new ArticleTypeBean();
String messages="";
String href="";
String forward="";
typeBean.setId(MyTools.strToint(request.getParameter("typeId")));
boolean mark=typeDao.operationArticleType("delete",typeBean);
if (mark) {
messages+="<li>刪除類別成功!</li>";
href="<a href='ArticleServlet?action=typeSelect'>[繼續刪除其他類別]</a>";
forward="/admin/success.jsp";
} else {
messages+="<li>刪除類別失敗!</li>";
href="<a href='javascript:window.history.go(-1)'>[返回]</a>";
forward="/admin/error.jsp";
}
request.setAttribute("messages",messages);
request.setAttribute("href",href);
RequestDispatcher rd = request.getRequestDispatcher(forward);
rd.forward(request, response);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -