Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By gimbal2

Thread: css file doesn't load in jsp when I called it through servlet RequestDispatcher

  1. #1
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    30
    Rep Power
    0

    Default css file doesn't load in jsp when I called it through servlet RequestDispatcher

    I have a html page which takes a username and password from the user and sent it to servlet if Both of them correct, then servlet dispatch to jsp page.

    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 received 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

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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: css file doesn't load in jsp when I called it through servlet RequestDispatcher

    Does that css file exist in that location?
    What happens if you copy and paste that url into your browser?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    30
    Rep Power
    0

    Default Re: css file doesn't load in jsp when I called it through servlet RequestDispatcher

    Hi yes it is ,when I run jsp page without dispatcher ,It loads with css .

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: css file doesn't load in jsp when I called it through servlet RequestDispatcher

    The difference is that in your dispatcher you are doing a forward, while if you just "run" the JSP it will be an actual navigation to that page. Check the url when you go through the dispatcher, you will see the browser does not in fact point to the JSP you are forwarding to.

    My guess is that the difference in URL is how the CSS cannot be found. What does the JSP source look like that loads the CSS file?
    mohsen.noor likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    mohsen.noor is offline Member
    Join Date
    Dec 2012
    Posts
    30
    Rep Power
    0

    Default Re: css file doesn't load in jsp when I called it through servlet RequestDispatcher

    Thanks everyone
    I found error
    In link tag I did not mention correct type ="text/css"
    <link rel="stylesheet" href="css/forms.css" >====> <link rel="stylesheet" type="text/css" href="css/forms.css" >

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: css file doesn't load in jsp when I called it through servlet RequestDispatcher

    That would be highly strange if that made any difference; you yourself said everything worked just fine when you navigated directly to the JSP - which would then still not have any specific type at that point in time.

    You probably changed something else that made the problem go away.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2014, 04:35 PM
  2. Load a file doesn't start a timer
    By warchieflll in forum Advanced Java
    Replies: 13
    Last Post: 02-03-2011, 08:34 PM
  3. Replies: 1
    Last Post: 12-11-2010, 08:25 PM
  4. doPost() is not called in servlet logic
    By bubulina in forum Java Servlet
    Replies: 6
    Last Post: 10-28-2009, 10:19 AM
  5. load xml file in servlet help please
    By khdani in forum Java Servlet
    Replies: 2
    Last Post: 10-05-2009, 10:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •