• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to access jsp from HTML

 
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I have a jsp file which i have added in to the WEB-INF directoy: WEB-INF/test.jsp
I am trying to access it through HTML So i did
<form method="POST" name="test" action="/WEB-INF/test.jsp">

But it didn't work.
Is it not the correct way to do it? Is it not possible? Do I need to create a servlet and use it ?
Please can some one help me out.
Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anything under WEB-INF cannot be accessed via a URL.

You could move the JSP out from under WEB-INF, but I would advise against it. The proper way to serve JSPs is by having a servlet controller, and keeping the JSPs hidden under WEB-INF. Please read this article for details on how to properly structure Java web applications.
 
Jeena Jeen
Ranch Hand
Posts: 65
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thats what i was thinking. I need a servlet to access it.
Will make a servlet

Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would be best.
 
Jeena Jeen
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So from servlet if i want to pass some paramters to the test.jsp I will do it through RequestDispatcher but what should be the path?
Should i write RequestDispatcher view = request.getRequestDispatcher("test.jsp");
or
RequestDispatcher view = request.getRequestDispatcher("/test.jsp");
 
Jeena Jeen
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please can some one help
Here is the structure of my files:
    ProjectA
         src
             FirstServlet.java
        Web-Content
             test1.html
             WEB-INF
                  test.jsp

Fist I have start my test1.html: WHich is sccuessful: It take me to the servlet: FirstServlet.java
But after i enter the values in and press enter I expect it to forward me to test.jsp
This is how it is done in my servlet

             

But i am getting error:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Please can someone help me;

Thanks..

 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeena Jeen wrote:Please can some one help
Here is the structure of my files:
    ProjectA
         src
             FirstServlet.java
        Web-Content
             test1.html
             WEB-INF
                  test.jsp

Fist I have start my test1.html: WHich is sccuessful: It take me to the servlet: FirstServlet.java
But after i enter the values in and press enter I expect it to forward me to test.jsp
This is how it is done in my servlet

             

But i am getting error:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Please can someone help me;

Thanks..



The highlighted portion itself tells you the problem.  You can't access it like that.  You need to create a url mapping for  /WEB-INF/test.jsp in web.xml file and access that url in request dispatcher.
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:You need to create a url mapping for  /WEB-INF/test.jsp in web.xml file and access that url in request dispatcher.


No, a mapping of the JSP page is not necessary. It should work just like that. Line 6 needs to be removed, of course - calling the dispatcher twice won't do any good.

Which URL are you trying to access, and how is that mapped to the servlet? Post the excerpt from web.xml that shows both parts of the mapping.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:You can't access it like that.


Incorrect. Forwarding to the JSP from its page controller is the proper way to display the JSP view.
reply
    Bookmark Topic Watch Topic
  • New Topic