Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 66724
167
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: 66724
167
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: 4552
112
  • 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: 66724
167
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!