尝试传递jsp页面时找不到资源错误

时间:2014-03-10 10:36:26

标签: java jsp servlets

我正在使用部署在jboss(6.0.2 EAP)

上的war文件的resteasy工作

我有以下工作流程:

  1. 网址匹配称为servlet(doGet() method)
  2. 这个servlet应该将jsp页面传递给客户端

    JSP页面位于WebContent/customFolder

    我使用requestDispatcher().forward()方法来调用JSP

    forward("/customFolder/name_of_jsp")

  3. 中给出的路径
  4. jsp有一个表单,其action属性指向另一个servlet
  5. 问题是,一旦调用forward()方法,浏览器就会返回404资源未找到错误。

    我已经关注了此论坛上已发布的一些问题,但无法解决此问题。

    任何人都可以指导我。

    编辑: JSP页面:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1" import="javax.servlet.*,java.lang.String"%>
    <!DOCTYPE html> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Password Reset Page</title>
    
    </head>
    <body>
    <form method="GET" action="Resteasy">
    <%!String userId;%>
    <%userId = (String)getServletContext().getAttribute("userid"); %>
    <p>User Id:<%= userId %></p>
    Password: <input type="password" name="pwd" id="pass">
    <br>
    Confirm Password: <input type="password" name="rePwd" id ="c_pass" onblur="confirmPass()"><br>
    <script type="text/javascript">
        function confirmPass() {
            var pass = document.getElementById("pass").value
            var confPass = document.getElementById("c_pass").value
            if(pass != confPass) {
                alert('Wrong confirm password !');
                document.getElementById("c_pass").focus();
            }
        }
    </script>
    <input type="submit" value="Submit">
    </form> 
    </body>
    </html>
    

    必须提供jsp的servlet:

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            log.info("Received request for popup jsp page");
    
            String userId = request.getParameter("userid");
            String utc = request.getParameter("utc");
    
            log.info("Recieved userid = "+ userId);
            log.info("Received utc is = "+ utc);
    
    
            ServletContext requestContext = request.getServletContext();
            requestContext.setAttribute("userid", userId);
            requestContext.setAttribute("UTC", utc);
    
    
            String htmlfileName = null; 
    
    
            try {
    
                htmlfileName =   new DeltaPropertyHandler(
                        DeltaConstants.LINK_HTML_FILE).getPropertyValue(DeltaConstants
                                .USER_PASSWORD_RESET_HTML);
                File file = new File(requestContext.getRealPath(htmlfileName));
                if(file.exists()){log.debug("file exists!!");}
                else{log.warn("file does mot exist");}
    
            } catch (Exception e) {
    
                log.error("failed to present the jsp page " + e.getMessage());
            }
           log.info("File name is "+htmlfileName);
    
           RequestDispatcher rd = requestContext.getRequestDispatcher(htmlfileName);
    
           rd.forward(request, response);
    
        }
    

1 个答案:

答案 0 :(得分:0)

您的代码:

RequestDispatcher rd = requestContext.getRequestDispatcher(htmlfileName);

你应该改变:

RequestDispatcher rd = requestContext.getRequestDispatcher(programname.jsp); 

如果您使用获取方法如下:

RequestDispatcher view=request.getRequestDispatcher(forward);
            view.forward(request, response);

如果您使用发布方法,如:

private static String LIST_USER="/listUser.jsp";

        RequestDispatcher view=request.getRequestDispatcher(LIST_USER);
        request.setAttribute("users", dao.getAllUsers());
        view.forward(request, response);

用户将从此格式引用。只需看看简单格式如下:

  A.jsp> conntroller.java > dao.java>dbUtil.java 

您希望该列表的引用如下所示 link to click