aspose file tools*
The moose likes JSP and the fly likes How do i use JSP include pag tag to include a java class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How do i use JSP include pag tag to include a java class file" Watch "How do i use JSP include pag tag to include a java class file" New topic
Author

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

Abhishek Dhar
Greenhorn

Joined: Nov 07, 2006
Posts: 16
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


Regards From ---- @bhishek Dh@r
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
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

Joined: Apr 20, 2002
Posts: 510
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

Joined: Nov 07, 2006
Posts: 16
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

Joined: Apr 20, 2002
Posts: 510
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

Joined: Nov 07, 2006
Posts: 16
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

Joined: Apr 20, 2002
Posts: 510
I have explained what to do. I will not do it for you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
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

Joined: Aug 24, 2007
Posts: 62
Make sure you give the relative URL in page attribute
<jsp:include page="relativeURL"/>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do i use JSP include pag tag to include a java class file