1

我在转发时遇到了一些问题,即使我正在转发,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.jspof 时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
4

2 回答 2

4

WEB-INF 中的文件不能直接从客户端访问。

一种方法是改变

 <a href="SomeServletmapping">

在 SomeServlet get 方法里面做

request.getDispatacher(yourJSP).forward();

第二种方式:

move those JSPs outside the WEB-INF folder.
于 2012-08-08T03:27:01.527 回答
1

看看这里

<a href="WEB-INF/results/adminAddNewEmployee.jsp">Press here to continue</a>

根据规范,文件夹directly内的任何内容都无法访问() 。WEB-INF

可以使用

<%@ include file="WEB-INF/path/to/expected.jsp" %>

JSP使用 request dispather 或使用类似的框架进行调度Spring

于 2012-08-08T03:26:14.747 回答