日期:2014-05-17 浏览次数:20757 次
package servlet;
import database.DBConnector;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import dto.Information;
public class AddInfor extends HttpServlet {
public AddInfor() { }
@Override
public void destroy() {super.destroy();} //重写destroy方法
@Override
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response); // 将Get请求转发至doPost
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
Information information=null ;
if(request.getParameter("name")==null||request.getParameter("subject")==null) //?????
session.removeAttribute("information");
else{
information= new Information();
information.setSubject(request.getParameter("subject"));
information.setContent(request.getParameter("content"));
information.setName(request.getParameter("name"));
information.setEmail(request.getParameter("email"));
information.add();
session.setAttribute("information",information);
}
//在这个地方无法跳转,不知道怎么回事。。。
response.sendRedirect("/Websource/index.jsp?page=1"); //请求跳转至主页
}
public void init() throws ServletException{ } //重写init方法
}