Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Unable to access js file from jsp.

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to access js file from jsp.

    Hi Champs,

    I am new to web development and working on a web based application. I am trying to access js file from jsp but getting 404 error.
    The project structure is
    HTML Code:
     Application
           |_ _ _ javasource
    
           |_ _ _ WebContent
                           |_ _ _ js
                                     |_ _ _ home.js
                           |_ _ _ META-INF
                           |_ _ _ WEB-INF                                                 
                                        |_ _ _ jsp
                                                  |_ _ _ home.jsp
                                        |_ _ _ lib
                                        |_ _ _ web.xml
                                        |_ _ _ struts-config.xml
    context path : /context/test

    I am trying to access home.js from home.jsp
    using :
    <script type="text/javascript" src="${contextPath}/js/home.js"></script>

    URL : http://localhost:8080/context/test/

    Please let me know how do we access js file from jsp?

    Thanks,
    Chinnu


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Unable to access js file from jsp.

    move the folder js inside WEB-INF and accordingly change the path of js in the jsp...better to give relative path with reference to the container

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unable to access js file from jsp.

    you stay at home.jsp?
    src="../../../js/home.js"

  4. #4
    Junior Member
    Join Date
    Jul 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unable to access js file from jsp.

    Dear chinnu , do one thing.Please move your "js" folder , inside WEB-INF folder.It is the standard method to build a project directory.
    :-)
    Then use this link to access your ".js" file.

    ../js/home.js

    (Nb: The ../ means to go to the parent directory relative to where you actually is.This will move you to WEB-INF folder.Then we are entering to the "js" folder and we are calling the "home.js" file)
    Hope it will help !!

Similar Threads

  1. Replies: 1
    Last Post: February 8th, 2012, 12:08 AM
  2. Unable to view jsp pages through same login page
    By Rajiv in forum Web Frameworks
    Replies: 1
    Last Post: August 17th, 2011, 11:43 AM
  3. [SOLVED] I am unable to read radio button actions in JSP
    By abhiM in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 17th, 2011, 01:41 AM
  4. Replies: 1
    Last Post: June 9th, 2011, 08:51 AM
  5. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM

Tags for this Thread