Jsp does not recognize Javascript files

0

I'm doing a web application with JavaEE and I need to pass certain parameters from a Servlet to a Jsp, I do it like this:

request.setAttribute("car", per.getCarrera().getNombre());

And for the redirection:

request.getRequestDispatcher("/odontologia/Tratamiento.jsp").forward(request,response);

The problem is that doing it in this way does not recognize the links to Javascript files that are on the JSP page, they are declared as follows:

<script src="../assets/js/plugins.js"></script>

I have also tried with Absolute routes but it still does not link the .js

<script src="<%=request.getContextPath()%>/assets/js/plugins.js"></script>

If the redirection was done with:

response.sendRedirect();

I recognize the .js files but I can not send the parameters. Any way to do this without using the session? and another question On what occasions is it correct to use the session to pass the variables from the Servlet to Jsp?

    
asked by MALWAREBITS 20.10.2018 в 23:05
source

1 answer

1

JSP has nothing to do with the JS. The browser receives HTML (which comes from JSP or does not care) and when processing it and see it includes resources (which can be JS or image files or any other) calculates the URLs of those resources and makes the corresponding requests.

The two methods you use mean completely different things:

  • sendRedirect returns a HTTP Redirect code (302) with the URL to the browser; the browser makes another request to the address indicated.

  • forward does not return anything to the browser. What it does is pass that same request to another component so that it can continue processing it

If you send a request to link :

  • A redirect to link will make your browser make a request to this URL and display the result. The URL of the browser will be link

  • A forward to link will cause the server to invoke "eljsp.jsp" within the same request to "index" return the result within the same request to "index". The URL of the browser is maintained in link .

So look at the browser URL. That will tell you what resource you are accessing, and what is the relative URL that has to appear in the HTML to access the JS.

    
answered by 21.10.2018 / 00:49
source