• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have explained what to do. I will not do it for you.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you give the relative URL in page attribute
<jsp:include page="relativeURL"/>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic