servlet能更新数据,不能跳转到目标页面?

qxhan1128 2006-12-21 10:09:11
//doGet()
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
Connection con=DataBaseConnection.getConnection();


//获取参数
String action=(String)request.getParameter("action");

if (action.equals("all"))
{
try
{
Collection ret=new ArrayList();
Statement stm=con.createStatement();
ResultSet rst=stm.executeQuery("select * from shengshi where c2_id=0 order by orderid desc");
while (rst.next())
{
CityVO cvo=new CityVO();
cvo.setC1_id(rst.getInt("c1_id"));
cvo.setC2_id(rst.getInt("c2_id"));
cvo.setTitle(rst.getString("title"));
cvo.setOrderid(rst.getInt("orderid"));
ret.add(cvo);
}
rst.close();
stm.close();

request.setAttribute("cvos",ret);
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/city/index.jsp");
requestDispatcher.forward(request,response);
}
catch(Exception e)
{
e.printStackTrace();
}
}
else if(action.equals("save"))
{
try
{
//获取全部ID分离
String total_c1_id=(String)request.getParameter("total_c1_id");
String[] temp_c1_id=split(total_c1_id,",");
for (int i=0;i<=temp_c1_id.length;i++)
{
//ID转换为数字类型
int c1_id=0;
try
{
c1_id=Integer.parseInt(temp_c1_id[i]);
}
catch(Exception e)
{
c1_id=0;
}
PreparedStatement stm=con.prepareStatement("update shengshi set title=?,orderid=? where c1_id=?");
stm.setString(1,(String)request.getParameter("title"+c1_id));
stm.setInt(2,Integer.parseInt(request.getParameter("orderid"+c1_id)));
stm.setInt(3,c1_id);
stm.executeUpdate();
stm.close();

}

//response.sendRedirect("/city.do?action=all");
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/city.do?action=all");
requestDispatcher.forward(request,response);

}
catch(Exception e)
{
e.printStackTrace();
}
}
}


第一个跳转正常:
request.setAttribute("cvos",ret);
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/city/index.jsp");
requestDispatcher.forward(request,response);
程序自动跳转到/city/index.jsp

第一个数据更新,显示空白页:

RequestDispatcher requestDispatcher=request.getRequestDispatcher("/city.do?action=all");
requestDispatcher.forward(request,response);

请兄弟们看看是什么问题,谢谢~~
...全文
159 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cloudgamer 2006-12-21
  • 打赏
  • 举报
回复
太长了

81,094

社区成员

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

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