1. struts2中從WEB-INF下的頁面直接超鏈接到WebRoot目錄下的頁面,
jsp頁面中可以設置如下:
<a href="../main.jsp">HomePage</a>
在當前路徑爲http://127.0.0.1:8088/LYDF/department/departmentList.action,則執行超鏈接“HomePate”後就會跳轉到http://127.0.0.1:8088/LYDF/main.jsp路徑,即main.jsp頁面。
當然,我們也可以用 <a href="${pageContext.request.contextPath}/main.jsp">HomePage</a>,會達到同樣的效果。
2. 當希望通過點擊按鈕或超鏈接後直接跳轉到一個指定頁面時,頁面設置可以如下:
<input type="button" οnclick="location='toAdd.action'" value="添加"/>
(或<a href="toAdd.action">添加</a>
配置文件struts.xml中可以設置如下:
<package name="department" extents="struts-default">
<action name="toAdd">
<result>/WEB-INF/department/department_add.jsp</result>
</action>
...
</package>
而當你通過執行一個方法需要跳轉到一個action下,如在添加頁面中填寫好資料後,
jsp頁面代碼:
<form action="addDepartment.action" method="post">
...
</form>
配置文件struts.xml中可以設置如下:
<package name="department" extents="struts-default">
<action name="departmentList" class="departmentAction" method="findAllDep">
<result name="list">/WEB-INF/department/department_list.jsp</result>
</action>
<action name="addDepartment" class="departmentAction" method="add">
<result name="input">/WEB-INF/department/department_add.jsp</result>
<result name="addSucce" type="redirect">departmentList.action</resutlt>
</action>
...
</package>