This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i use JSP include pag tag to include a java class file

 
Abhishek Dhar
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends, actually let me come straight to the point. I just was experimenting with the jsp:include page =..... tag in jsp
I know that we can use this tag to include .html, .js, .jsp file but what about if I want to include output of a servlet code as shown below into a .jsp page using this tag Is It Possible To Do So???



Now I use a one line code in my .jsp page as


But I use to get a error saying "The requested resource not avilable"

Please help me out if anybody knows how to perform out this work
 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The address of the included page is the same address that you would use to hit the page from outside of your application (for example - direct from the browser) but without the host and context root.

What URL is this Servlet mapped to?
 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A more important question is why are you trying to include a servlet into a JSP? This is kind of a backward idea. Usually JSPs include other JSPs.
 
Abhishek Dhar
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael Ku for your help but I didn't get what actually you want to explain me, can you please go a little bit deeper in the concept.

Actually I am designing a application using MVC model type 1. So according to that model i can directly create a connection between model and view. So i am designing some error pages which will be displayed as test (String) on the places in the application where its needed (like user name validation).

I have written the below given code in web.XML file for servlet file mapping

 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are attempting to go directly to the servlet class without going thru the servlet engine. This is not how web applications work.

Either change the servlet to a JSP (which it should be anyway, you should NEVER use a servlet to stream back html - that is what a JSP is for) or use JSTL to execute the servlet and include the result of its execution.

Have you tried either of these approaches?
 
Abhishek Dhar
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not quite familiar with JSTL so can't go on that path

the 2 one you said convert Servlet to JSP so how would i do that thing can you explain me up

anyways thank you for all your help
 
Michael Ku
Ranch Hand
Posts: 510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have explained what to do. I will not do it for you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhishek Dhar:
I am designing a application using MVC model type 1.
There is no such thing. Model 1 is not MVC. The web app approximation of MVC is Model 2.

Is there a reason that you are using this unconventional approach rather than using accepted best-practice patterns? Michael is giving you good advice.

i am not quite familiar with JSTL so can't go on that path
There's no time like the present to learn essential JSP technologies.
 
paritosh ranjan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you are using MVC pattern.You are trying to implement view in a servlet.This only breaks the MVC pattern,you should write view in a JSP,there should be no view part in a servlet.Servlets are used as controllers,so write your view part in a jsp and include that jsp file.That will be the correct MVC model.
 
paritosh ranjan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you give the relative URL in page attribute
<jsp:include page="relativeURL"/>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic