📄 600a40835a17001c1d9c982b3310814d
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package edu.neu.struts.action;
import java.io.UnsupportedEncodingException;
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.hibernate.Transaction;
import edu.neu.sspp.TextAreaConventer;
import edu.neu.sspp.hibernate.HibernateSessionFactory;
import edu.neu.sspp.hibernate.TComment;
import edu.neu.sspp.hibernate.TCommentDAO;
import edu.neu.sspp.hibernate.TProject;
import edu.neu.sspp.hibernate.TProjectDAO;
import edu.neu.sspp.hibernate.TTeacher;
import edu.neu.sspp.hibernate.TTeacherDAO;
import edu.neu.sspp.hibernate.TUser;
import edu.neu.sspp.hibernate.TUserDAO;
import edu.neu.struts.form.CommentForm;
/**
* MyEclipse Struts
* Creation date: 06-10-2007
*
* XDoclet definition:
* @struts.action path="/comment" name="commentForm" input="/proj_jsp/proj_info.jsp" scope="request" validate="true"
*/
public class CommentAction 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
try {
commentForm.setNick(new String(commentForm.getNick().getBytes("ISO-8859-1"), "UTF-8"));
commentForm.setContent(new String(commentForm.getContent().getBytes("ISO-8859-1"), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(commentForm.getContent());
System.out.println(commentForm.getNick());
System.out.println(commentForm.getProjID());
System.out.println(commentForm.getUrl());
System.out.println(commentForm.getUnknow());
TComment comment = new TComment();
TCommentDAO commentDAO = new TCommentDAO();
String content = TextAreaConventer.convertToHtml(commentForm.getContent());
if(content.length() > 500)
content = content.substring(0, 500);
comment.setContent(content);
if(!commentForm.getUnknow())
comment.setIsUser(new Byte((byte)1));
else
comment.setIsUser(new Byte((byte)0));
if(commentForm.getNick() == null ||
commentForm.getNick().equals("") ||
commentForm.getUnknow())
comment.setNick("匿名");
else {
//身份验证
String login = (String)request.getSession().getAttribute("");
if(login == null) {
comment.setNick(commentForm.getNick());
}
else if(login.equals("user")) {
TUserDAO userDAO = new TUserDAO();
TUser user = userDAO.findById((String)request.getSession().getAttribute("id"));
if(user.getNick().equals(commentForm.getNick()))
comment.setNick(commentForm.getNick());
}
else if(login.equals("teacher")) {
TTeacherDAO teacherDAO = new TTeacherDAO();
TTeacher teacher = teacherDAO.findById((String)request.getSession().getAttribute("id"));
if(teacher.getRealName().equals(commentForm.getNick()))
comment.setNick(commentForm.getNick());
}
else {
//异常情况
System.out.println("running here");
return null;
}
}
comment.setDate(new Date());
TProjectDAO projectDAO = new TProjectDAO();
TProject project = projectDAO.findById(commentForm.getProjID());
project.setCount(project.getCount() + 1);
comment.setTProject(project);
Transaction transaction =
HibernateSessionFactory.getSession().beginTransaction();
commentDAO.save(comment);
transaction.commit();
HibernateSessionFactory.closeSession();
return mapping.findForward(commentForm.getUrl());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -