This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
 
Author and ninkuma
Marshal
Posts: 66801
168
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
Author and ninkuma
Marshal
Posts: 66801
168
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: 1878
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: 4744
117
  • 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
Author and ninkuma
Marshal
Posts: 66801
168
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!