请问,这个页面为何无法跳转?

止境 2012-11-19 11:46:33
上一个页面在文本框中输入内容,提交后插入数据库,这部分都可以成功,而且数据的更新一切正常,但是为何无法转入index的第一页?请大神指教。
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方法
}

...全文
297 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
AlisaHWT 2012-11-21
  • 打赏
  • 举报
回复
information.add();这个是什么,add什么东西?这个方法里是不是有没执行的
时光的留念 2012-11-21
  • 打赏
  • 举报
回复
相对路径写全试试 response.sendRedirect("../Websource/index.jsp?page=1");
BoJerry 2012-11-21
  • 打赏
  • 举报
回复
如果跳转这个语句没有执行,那就是你前面代码出来问题。
Jamps 2012-11-21
  • 打赏
  • 举报
回复
你把index.jsp放到根目录下,再改成response.sendRedirect("index.jsp");试试看看能不能跳过去
  • 打赏
  • 举报
回复
response.sendRedirect("/Websource/index.jsp?page=1");用这个写一个简单的测试。看下路径什么的有没有问题。测试类能跳转的话,再找其他地方。
小小都不懂 2012-11-21
  • 打赏
  • 举报
回复
引用 10 楼 hc1104 的回复:
myeclipse怎么用断点的方法来测试这段代码?
myeclipse 中 双击你要查看的代码行 就设置断点了 之后 F6 单步调试吧
止境 2012-11-21
  • 打赏
  • 举报
回复
myeclipse怎么用断点的方法来测试这段代码?
青柠loft 2012-11-20
  • 打赏
  • 举报
回复
return new ActionForward("/Websource/index.jsp?page=1"); 要不试试这个?
orangleliu 2012-11-20
  • 打赏
  • 举报
回复
是没转,还是转了404??
fengyingkong 2012-11-20
  • 打赏
  • 举报
回复
你用绝对路径试试 !!!
BoJerry 2012-11-20
  • 打赏
  • 举报
回复
页面无法跳转的话,情况可能有多种: 1.你先确定这句代码有没有执行; 2.如果执行了,无法跳转,看该页面是否报错!
止境 2012-11-20
  • 打赏
  • 举报
回复
引用 1 楼 BoJerry 的回复:
页面无法跳转的话,情况可能有多种: 1.你先确定这句代码有没有执行; 2.如果执行了,无法跳转,看该页面是否报错!
这句话没有执行而且页面也不报错,只是进入这个页面后 不跳转,插入数据一切都正常.
止境 2012-11-20
  • 打赏
  • 举报
回复
引用 2 楼 fengyingkong 的回复:
你用绝对路径试试 !!!
绝对路径也不行...

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧