📄 addcommentaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package org.openblog.struts.comment.action;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.openblog.hibernate.ArticleDAO;
import org.openblog.hibernate.Comment;
import org.openblog.hibernate.CommentDAO;
import org.openblog.struts.comment.form.CommentForm;
/**
* MyEclipse Struts
* Creation date: 01-19-2009
*
* XDoclet definition:
* @struts.action path="/addComment" name="commentForm" scope="request"
*/
public class AddCommentAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CommentForm commentForm = (CommentForm) form;// TODO Auto-generated method stub
Date date = new Date();
String format = "yyyy年MM月dd日 HH:mm";
SimpleDateFormat sdf = new SimpleDateFormat(format);
String nowDate = sdf.format(date);
Comment comment = new Comment();
comment.setCommentContent(request.getParameter("commentcontent"));
comment.setCommentEmail(request.getParameter("commentmail"));
comment.setCommentName(request.getParameter("commentname"));
comment.setCommentUrl(request.getParameter("commenturl"));
comment.setCommentDate(nowDate);
comment.setArticle(new ArticleDAO().findById(Integer.valueOf(request.getParameter("articleid"))));
comment.setCommentStatus(new Integer(0));
new CommentDAO().save(comment);
try {
response.sendRedirect("../../showarticle.jsp?articleid="+request.getParameter("articleid"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -