我在转发时遇到了一些问题,即使我正在转发,JSP 文件也拒绝转发:我从这里开始:
索引.html:
<!DOCTYPE html>
<html>
<head><title>Bank application</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<table class="title">
<tr><th>Web Bank application</th></tr>
</table>
<br/>
<fieldset>
<legend>Login Page - please enter your Username and Password</legend>
<form action="loginPage">
Username: <input type="text" name="username"><br>
Password : <input type="text" name="password"><br>
<input type="submit" value="Login">
</form>
</fieldset>
<br/>
<br/>
<br/>
<br/>
<br/><br/><br/><br/><br/><br/>
</body></html>
与屏幕:
然后我转到那个 JSP 文件 - adminPage.jsp:
<!DOCTYPE html>
<html>
<head><title>System Administrator Page</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
</head>
<body>
<h1>Hello ${name.firstName} ${name.lastName} , You've logged in successfully!</h1>
<h1>
Please choose one of the following options
</h1>
<fieldset>
<legend>Add a new manager to the bank system</legend>
<form action="adminAdds1">
<a href="WEB-INF/results/adminAddNewManager.jsp">Press here to continue</a>
</form>
</fieldset>
<fieldset>
<legend>Add a new employee to the bank system</legend>
<form action="adminAdds2">
<a href="WEB-INF/results/adminAddNewEmployee.jsp">Press here to continue</a>
</form>
</fieldset>
</body></html>
用那个屏幕:
但是当我单击两个选项之一并移至adminAddNewEmployee.jsp
of 时adminAddNewManager.jsp
,我一遍又一遍地得到这个,即使两个文件都位于同一文件夹中 adminPage.jsp
:
HTTP Status 404 -
--------------------------------------------------------------------------------
type Status report
message
description The requested resource () is not available.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.28
项目树在哪里:
我怎样才能解决这个问题 ?我知道 WEB-INF 需要一些转发,但我应该把转发放在哪里?在 JSP 中?
但请注意,我使用href
它仍然失败。
问候
编辑:
在 adminPage.jsp 中添加:
<fieldset>
<legend>Add a new manager to the bank system</legend>
<form action="adminAdds1">
<a href="src/servlets/Admin1">Press here to continue</a>
</form>
</fieldset>
并创建了一个新的 servlet Admin1.java
:
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/adminAdds1")
public class Admin1 extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
request.getRequestDispatcher("/WEB-INF/results/adminPage.jsp").forward(request, response);
}
}
但是当我再次运行所有东西时,我得到:
HTTP Status 404 - /WebBank/src/servlets/Admin1
--------------------------------------------------------------------------------
type Status report
message /WebBank/src/servlets/Admin1
description The requested resource (/WebBank/src/servlets/Admin1) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.28