• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

calling html and jsp from Servlet

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
how to call a html from a servlet ?
i dont want to write html code in the servlet.
i want to call the seperate html file.
also how can i call jsp from a servlet?
sample code is welcome .
thanx in advance ,
Srikanth
 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see follow:
getServletContext().getRequestDispatcher("/xxx.jsp or /xxx.html").forward(req,resp);
or.........................include(req,resp);
or resp.sendRedirect("xxx.jsp or xxx.html");
the three method all can implement your requirement,but the forward(....) and include(....) method run in serverside,the sendRedirect() method send the response to your browser to redirect to other page
 
s srikanth
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx cong
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you pls tell me what is the difference between 'forward' and 'include'? I read the doc but i dont understand

Originally posted by zb cong:
see follow:
getServletContext().getRequestDispatcher("/xxx.jsp or /xxx.html").forward(req,resp);
or.........................include(req,resp);
or resp.sendRedirect("xxx.jsp or xxx.html");
the three method all can implement your requirement,but the forward(....) and include(....) method run in serverside,the sendRedirect() method send the response to your browser to redirect to other page

 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
with the forward command you simply pass on the request and the response to another servlets or jsp to take care of.
with the include command you include the servlets or jsp output in your page after it has done its stuff.
basically most of the time you get the same result, its only semantics.
most of time you use include so you can embedd a lot of servlets or jsp together.
you must remember that if u use forward you ae not allowed to output anything to the client before you call forward (meaning you can't use the response in your servlets if u use forward).
 
Tazzmission
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
So 'forward' just pass the control to another Servlet? (Also, pass all the request parameter of from original servlet to another servlet too?)
And it seems that include is more flexible?
Thank You.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correct
btw, in jsp you have two kind of include.
you can use the include attribute
<% @include
or the include tag :
<jsp:include
the difference is that the first one is included in compile time (only once) while the second is at runtime when the page is loaded, so it is even more flexible.
hope it helped to clear this stuff a bit
 
Tazzmission
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much.
I will try them later when I've time.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic