2013-03-20 26 views
1

我正在將我的請求從Login servlet轉發到位於faculty文件夾(它是子文件夾)中的FacultyHomePage.jsp ....顯示頁面,但url仍爲/ LoginServlet。 爲什麼不更改網址?即使在servlet中請求調度之後,URL也不會更改

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); 
      } 
+2

因爲你做了** **着我 – 2013-03-20 08:04:24

+0

是新來這個concept.Please你能解釋一下如何改變網址? – Vini 2013-03-20 08:07:31

+0

檢查我的答案。 – 2013-03-20 08:10:42

回答

4

request對象不會在請求調度程序中創建。檢查RequestDispatcher.forward方法。

如果你想有一個URL變化,然後使用response.sendRedirect(java.lang.String)

+1

是thnx,這是工作,但現在我沒有得到在我的登錄servlet創建的會話。這與sendRedirect()有關? – Vini 2013-03-20 08:15:21

+0

你可以使用'session = request.getSession(true)'語句強制地獲得會話;'在此之前,你可以檢查一個會話是否已經使用if(session!= null){session = request.getSession(true); }'。 – 2013-03-20 08:18:05

+0

@Vini你的意思是你沒有獲得會話存儲值 – 2014-12-24 15:39:41

相關問題