java - JSP path error on servlet redirect -


I'm new to Java Web Development when I use JSP redirect from servlet, did not load images and CSS files goes. Without servlet it is working well, but when I want to use servlet which is not working. The CSS file is with JSP one in the same folder Please help me how should I set the href attribute of the link tag?

  & lt; Link rel = "stylesheet" type = "text / css" href = "/ style.css" & gt;   

The servlet contains only 1 command:

  request.getRequestDispatcher ("index.jsp"). Forwarded (request, response);    

You are prompted to use redirect but you are using forwarding . Anyway, if the resources (CSS, JS, etc.) are not in the same path as your JSP, then you should append the reference reference for each of these. There are two ways:

  • Use only the expression language:

      & lt; Link rel = "stylesheet" type = "text / css" href = "$ {request.contextPath} /style.css" & gt;    
  • Use of tags:

      & lt; Link rel = "stylesheet" type = "text / css" href = "l: c: url value = '/ style.css' / & gt;" & gt; From your comment:  

    The problem was that I could not use servlet urlPatterns = {"/"} with this pattern

    Strong> can have a servlet with url pattern "/" . This means that your servlet handles every single request in your application, note that the requests for resources (CSS, JS, image etc.) are GET requests (you can easily verify it by opening a browser You can firefox with firebug or chrome, press F12 and check the Network tab to see all the requests made on the server) so that your servlet can handle them too. To use a single servlet in a similar manner, it will be so painful to handle manually, unless you want to implement it yourself (IMO should not try to do so unless you are you actually I know what are you doing).



Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -