servlet中如何自动跳到一个jsp页面?

pxpbb 2004-11-30 08:52:32
我在servlet中根据request的某个参数进行判断后,应该使客户端回到原来的jsp页面重输参数。请问除了使用response.sendredirect()之外,有无其他办法?
请问,response.sendredirect()的作用是否被用来实现此类功能?
请问,response.sendRedirect("http://192.168.0.188:8080/MYlogin.jsp");//重定向到登陆页面
此行代码有什么问题,我在本机器(192.168.0.188)执行不会报错。但在其它机器上访问192.168.0.188上的web服务时,执行到此处会报"找不到网页",HTTP 404 - 未找到文件,非常郁闷中,请求回答!!!!
...全文
328 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
pxpbb 2004-11-30
  • 打赏
  • 举报
回复
j2ee
wuqinxin 2004-11-30
  • 打赏
  • 举报
回复
用getServletContext().getRequestDispatcher("/user.jsp"); //user.jsp为你的页面的相对路径。
你要的是j2ee还是j2se的api文档?
pxpbb 2004-11-30
  • 打赏
  • 举报
回复
谢谢 yulchina及各位兄弟的回答,我觉得自己是该好好查差文档了,请各位给我一个下载sun的完整jdk文档的地址,
programdolt 2004-11-30
  • 打赏
  • 举报
回复
HttpServletRequest.getRequestDispatcher(java.lang.String path).forward(ServletRequest request, ServletResponse response)
易点互联 2004-11-30
  • 打赏
  • 举报
回复
那么这样呢?
response.setContentType("text/html");
PrintWriter out = res.getWriter();
out.write("<META http-equiv=refresh content='2;url=http://192.168.0.188:8080/MYlogin.jsp'>");
通过HTML代码跳转。

你可以:response.setHeader();
这样不能传递参数
易点互联 2004-11-30
  • 打赏
  • 举报
回复
可以使用requestDispatcher得forward();
若要传递参数可以用HttpSession

response.sendRedirect("http://192.168.0.188:8080/MYlogin.jsp")报错说明相应得站点不允许被应用,要运行被引用可以在context中加上crossContext="true"
kingmaxno1 2004-11-30
  • 打赏
  • 举报
回复
servelt中有专门用于转发的方法,你查一下,
yulchina 2004-11-30
  • 打赏
  • 举报
回复
javax.http.servlet.HttpServletResponse

Method sendRedirect

public void sendRedirect(java.lang.String location)
throws java.io.IOException


Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:

location - the redirect location URL

Throws:

java.io.IOException - If an input or output exception occurs
IllegalStateException - If the response was committed

另:
你应该写相对路径嘛!在没必要写觉得路径的时候,就尽量用相对路径!这样才能保证程序的移植的能力!
xitianjile 2004-11-30
  • 打赏
  • 举报
回复
那么这样呢?
response.setContentType("text/html");
PrintWriter out = res.getWriter();
out.write("<META http-equiv=refresh content='2;url=http://192.168.0.188:8080/MYlogin.jsp'>");
通过HTML代码跳转。
chengjunlin55555 2004-11-30
  • 打赏
  • 举报
回复
关注
steveyue 2004-11-30
  • 打赏
  • 举报
回复
好象forward()方法也可以重定向的,而且还可以传递参数

81,092

社区成员

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

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