4

I have a HTML page which takes a username and password from the user and sent it to servlet. If both of them are correct, then servlet dispatches to JSP page.

RequestDispatcher rD = request.getRequestDispatcher("dynamic/faculty/updatefaculty.jsp");
        rD.forward(request, response);

I check all pages separately and all of them work correct. CSS file load in jsp, but when I use dispatch, the CSS file does not load in JSP.

And of course I receive following from BrowserLog in NetBeans

Failed to load resource: the server responded with a status of 404 (Not Found) (04:11:01:478 | error, network)
 at http://localhost:8080/css/forms.css
mohsen.nour
  • 1,089
  • 3
  • 20
  • 27

3 Answers3

3

For a dynamic page you have to use this format:

link href="${pageContext.request.contextPath}/css/sample.css"

Static response has no values, use the format below. This will blindly redirect. response.sendRedirect("sample.jsp");

Singular1ty
  • 2,577
  • 1
  • 24
  • 39
3

To simplify your needs:

change in your updatefaculty.jsp

FROM: <link rel=stylesheet type="text/css" href="/css/forms.css">

TO: <link rel=stylesheet type="/text/css" href="<%= request.getContextPath() %>/css/forms.css">

alternatively: <%= request.getContextPath() %> -> ${pageContext.request.contextPath}


Explaination: Using this one - you will allow the XYZ.jsp (no matter from which web servlet you have came) to load form.css file to your page. You can stil keep using RequestDispatcher.forward(request, response) as (I may think) you need it for pass some attributes.

ehr
  • 143
  • 1
  • 1
  • 12
1

You can try this instead of using dipatcher

response.sendRedirect("dynamic/faculty/updatefaculty.jsp");
Mohammad Hammadi
  • 733
  • 2
  • 11
  • 34