facebook

difficulty finding the context path, why is this? [Closed]

  1. MyEclipse IDE
  2.  > 
  3. Installation, Configuration & Updates
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #203696 Reply

    According to the IDE, the project path root is sciReportsWeb, any references to anything below this only work if I use this approach in the jsp:

    <%
    String path = request.getContextPath();
    %>

    then I have to use path in url references like this

    <SCRIPT language=”javascript”
    src=”<%=path>/sci/sciReports.js”>
    </SCRIPT>

    I have to use this in any include, any url reference, but there are some places where I can’t even get this syntax to work. Problem is, I should not have to do this in the first place. Any references to “./sci/sciReports.js” or “/sci/sciReports.js” or “/sci/sciReports.js” or even “sciReports.js” just don’t work. What is happening?

    #203704 Reply

    Riyad Kalla
    Member

    I’m not terribly clear on what your question in… getContextPath will return the webapplication path w.r.t. to the application server to you so you can safely reference resources using an absolute path. Also please note that your code:

    
    src="<%=path>/sci/sciReports.js">
    

    is not valid, you are missing a ‘%’ character after the variable ‘path’, i.e.:

    
    src="<%=path%>/sci/sciReports.js">
    

    There is not really any magic going on here, if you are trying to reference a resource using “/sci/sciReports.js”, that means you are requesting from the root of your domain’s URL, in the sci directory, the resource sciReports.js, in Tomcat terms this means the url:
    http://localhost:8080/sci/sciReports.js

    which I imagine is invalid since you need to qualify a webapplication name (in your case ‘sciReportsWeb’).
    Also note that if you just specify ‘sciReports.js’, that means relative to where you loaded the page from, sciReports.js will be in the same location; which it doesn’t sound like it is either.

    As a first plan of attack, try and fix the expression tag, and then be more specific with what you are trying to do, the URL you are accessing, the code you are using, and the result you are getting and we can try and help you.

    #203712 Reply

    wouldn’t you know I picked the wrong example, sorry there are a ton of places in my code where it is correctly referenced. I think I will just pass the forward name back to the action class and let struts figure out the url. Thanks.

    #203713 Reply

    Riyad Kalla
    Member

    I’m still not clear on what the problem was, so lets pretend this never happened 😀

    #203721 Reply

    I will resubmit a new question when this problem resurfaces again. Thanks much!

    #203723 Reply

    Riyad Kalla
    Member

    Ok great, no problem.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: difficulty finding the context path, why is this? [Closed]

You must be logged in to post in the forum log in