servlet问题。页面不跳转,停在servlet页面,页面是空白的。 急啊~~~ 10
servlet代码:packageservlet;importjava.io.IOException;importjava.io.PrintWriter;importja...
servlet代码:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.*;
import db.DB;
public class AddServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
request.setCharacterEncoding("gb2312");
response.setContentType("gb2312");
String title=request.getParameter("title");
String content=request.getParameter("content");
User user=(User)request.getSession().getAttribute("user");
LyTable ly=new LyTable();
ly.setUserId(user.getId());
ly.setDate(new Date(System.currentTimeMillis()));
ly.setTitle(title);
ly.setContent(content);
if (new DB().addInfo(ly)){
response.sendRedirect("success.jsp");
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
doGet(request,response);
}
} 展开
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.*;
import db.DB;
public class AddServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
request.setCharacterEncoding("gb2312");
response.setContentType("gb2312");
String title=request.getParameter("title");
String content=request.getParameter("content");
User user=(User)request.getSession().getAttribute("user");
LyTable ly=new LyTable();
ly.setUserId(user.getId());
ly.setDate(new Date(System.currentTimeMillis()));
ly.setTitle(title);
ly.setContent(content);
if (new DB().addInfo(ly)){
response.sendRedirect("success.jsp");
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
doGet(request,response);
}
} 展开
3个回答
展开全部
if (new DB().addInfo(ly)){
response.sendRedirect("success.jsp");
}
两个错:1,条件不成立时没有跳转页面语句;2,你用的重定向,页面没有获得数据,应该用请求转发。
请求转发是把 修改过后的请求(request)转发给下一个页面,重定向是把修改之前的请求转发给下一个页面(准确地说,重定向是2个请求,请求转发是1个请求)
请求转发 RequstDispatcher("success.jsp").forward(request,response);
response.sendRedirect("success.jsp");
}
两个错:1,条件不成立时没有跳转页面语句;2,你用的重定向,页面没有获得数据,应该用请求转发。
请求转发是把 修改过后的请求(request)转发给下一个页面,重定向是把修改之前的请求转发给下一个页面(准确地说,重定向是2个请求,请求转发是1个请求)
请求转发 RequstDispatcher("success.jsp").forward(request,response);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询