Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to access jsp from HTML  RSS feed

 
Ranch Hand
Posts: 62
1
  • Mark post as helpful
  • send pies
  • 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
 
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 62
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be best.
 
Jeena Jeen
Ranch Hand
Posts: 62
1
  • Mark post as helpful
  • send pies
  • 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: 62
1
  • Mark post as helpful
  • send pies
  • 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..

 
Rancher
Posts: 1915
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • 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: 5038
134
  • Mark post as helpful
  • send pies
  • 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
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Trust God, but always tether your camel... to this tiny ad.
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!