【问题标题】:URL do not change even after request dispatching in servlet即使在 servlet 中发送请求后,URL 也不会改变
【发布时间】:2013-03-20 08:03:03
【问题描述】:

我将我的请求从登录 servlet 转发到位于学院文件夹(子文件夹)中的 FacultyHomePage.jsp....页面已显示,但 url 仍为 /LoginServlet。 为什么网址没有变化??

    HttpSession sc= request.getSession();
          if(usertype==0)
          {
              sc.setAttribute("type", usertype);
              sc.setAttribute("id",id );
         rd=request.getRequestDispatcher("/faculty/FacultyHomePage.jsp");
         rd.forward(request, response);
          }

【问题讨论】:

  • 因为你做了一个转发
  • 我是这个概念的新手。请你解释一下如何更改网址?

标签: servlets requestdispatcher


【解决方案1】:

新的request 对象不会在请求调度程序中创建。检查RequestDispatcher.forward方法。

如果您想更改网址,请使用response.sendRedirect(java.lang.String)

【讨论】:

  • 是的 thnx,这是有效的,但现在我没有在我的登录 servlet 中创建会话。这与 sendRedirect() 有关吗???
  • 您可以使用session = request.getSession(true); 语句强制获取会话。在此之前您可以使用if(session != null){session = request.getSession(true);} 检查是否已经创建了会话。
  • @Vini 你的意思是你没有得到会话存储的值
猜你喜欢
  • 2016-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多