我已經創建了一個web應用程序MyApp
。如何正確顯示瀏覽器中的原始URL
我有一個JSP roleAdd.jsp
它有一個表單提交到RoleAdd.do
的URL。
<form id="form_role_add" method="post" action="RoleAdd.do">
<label id="label_role_name">Role Name: </label>
<input type="text" id="role_name" name="role_name">
<label id="label_role_desc">Role Desc: </label>
<input type="text" id="role_desc" name="role_desc">
<button type="submit" id="button_add" name="button_add">Add</button>
</form>
在web.xml
我映射RoleAdd.do
網址RoleAddServlet
的servlet。
<servlet>
<servlet-name>RoleAddServlet</servlet-name>
<servlet-class>com.myapp.web.servlet.RoleAddServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RoleAddServlet</servlet-name>
<url-pattern>/RoleAdd.do</url-pattern>
</servlet-mapping>
在RoleAddServlet
的servlet,我轉發回roleAdd.jsp
。
RequestDispatcher view = request.getRequestDispatcher("roleAdd.jsp");
view.forward(request, response);
現在我在瀏覽器中輸入http://localhost:8080/MyApp/roleAdd.jsp。 JSP被加載。我在表單中輸入數據並點擊提交按鈕。它進入RoleAddServlet
servlet,然後轉發回roleAdd.jsp
。唯一的問題是瀏覽器現在顯示http://localhost:8080/MyApp/RoleAdd.do。
bowser顯示http://localhost:8080/MyApp/roleAdd.jsp有可能嗎?
如果是,那麼我需要做什麼?
如果不是那麼爲什麼?
由於
看看重定向工作,而不是:'response.sendRedirect是(「/ roleAdd.jsp」);' – CubeJockey
它工作,但我失去了我的屬性,這是我設置的請求對象'RoleAddServlet'的servlet。該屬性比瀏覽器中顯示的錯誤URL更重要。 – ChumboChappati