Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2004

Tip: Looking for answers? Try searching our database.

loading a servlet in a frame..

Thread view: 
Frances Del Rio - 26 Nov 2004 07:23 GMT
I have a frameset w/two frames, top frame is form, when user hits
'submit' I want servlet to load and execute in bottom frame..  if path
to servlet in url-pattern in web.xml is, say /myServlet, and in form I
have action=myServlet, how would I load the servlet into the bottom
frame?  thank you..  Frances
PerfectDayToChaseTornados - 27 Nov 2004 11:37 GMT
| I have a frameset w/two frames, top frame is form, when user hits
| 'submit' I want servlet to load and execute in bottom frame..  if path
| to servlet in url-pattern in web.xml is, say /myServlet, and in form I
| have action=myServlet, how would I load the servlet into the bottom
| frame?  thank you..  Frances

Hi Frances, I probably wouldn't use a frame :-) Frames have been deprecated
by W3C & are a real pain for usability (problematic for screen readers etc).
I would either return to the same jsp & have dynamic output in the bottom
part, or have the form as an include & include it in the submission & result
page. To do it using frames would be more complicated as your servlet would
have to return the frameset, you would then need to pick up attributes in
the jsp called from the bottom half of the frameset.

Also in regard to your previous post, the advantage of not being able to
"browse" to WEB-INF & it's subdirectories is security. It means that you can
control (via servlets) exactly what gets served from there. It is a pretty
common pattern to put secure jsps in subdirectories under the WEB-INF
directory.

HTH
Signature

-P
"Programs that are hard to read are hard to modify.
 Programs that have duplicated logic are hard to modify.
 Programs with complex conditional logic are hard to modify"

( Kent Beck)

Frances Del Rio - 29 Nov 2004 16:27 GMT
> | I have a frameset w/two frames, top frame is form, when user hits
> | 'submit' I want servlet to load and execute in bottom frame..  if path
[quoted text clipped - 9 lines]
> have to return the frameset, you would then need to pick up attributes in
> the jsp called from the bottom half of the frameset.

thank you for your response, TornadoChaser...  I had not seen it until
now..  you responded also to my other post, about how to do this (have
return stuff print on same window..) w/a jsp..  but I have not been able
to make that work..  I still want to do it, I'm learning and this app is
more a learning exercise than anything else..  I did manage to load the
servlet into another frame (frames -- deprecated?  sorry, I think that's
ridiculous, there's lots of cool stuff you can do w/frames if you use
them right..)  check it out..

    www.francesdelrio.com/hamlet..

it turns out it was quite easy, not a java question at all, all I had to
do was put "target='main'" (name of frame) in form tag to indicate I
want results of form submission to show up in other frame..  had no idea
until now you could put a target attr in form tag..  you never finish
learning little things.... ;)

I still want to make a jsp version of this (again, this is a learning
exercise..) so: maybe I can now still try do what you said and do it all
on one frame in jsp?  (the way it works now though, in servlet version
that loads in another frame, when user hits 'reload' it gets 'cleaned
up' and return disappears and bottom frame returns to being empty..
could I do this effect in jsp? w/everyting in same frame?)  here's
source code of current servlet..

   www.francesdelrio.com/java/hamlet.html

am trying to figure out how to best 'convert' this to jsp.. the
confusing part to me about what you sent me was how jsp 'reads' from
servlet.. this part..

<%  String myWord = (String) request.getAttribute("yourattributename");
        if(myWord == null){
            myWord = "";
        }      %>

how does jsp here know what servlet to read from?  I put everything you
wrote that time in a one-pg word file, for easier ref..  in case you
forgot what you wrote.. www.francesdelrio.com/java/how-to.doc..  thank
you again very much..  Frances
PerfectDayToChaseTornados - 30 Nov 2004 21:43 GMT
| > | I have a frameset w/two frames, top frame is form, when user hits
| > | 'submit' I want servlet to load and execute in bottom frame..  if path
[quoted text clipped - 50 lines]
| forgot what you wrote.. www.francesdelrio.com/java/how-to.doc..  thank
| you again very much..  Frances

Hi Frances,

The Servlet forwards to the jsp. So you still submit to a Servlet, the
Servlet does the processing & then forwards the request to the jsp, the jsp
then accesses the attributes you put in the request or session. It is best
to keep as much code out of jsps as possible & to do your processing in a
Servlet.

If you are still insistent on using frames ;-) then you will need to set the
attributes with session scope before you return the frameset, as the
frameset then makes a new HTTP request for each contained frame. You can
then access the attributes in the jsp, but you will probably also want to
remove them from the session after using them with
session.removeAtrribute(attname).

As for includes, you can include jsp content in other jsps, see these links
here for details
http://java.sun.com/products/jsp/syntax/1.1/syntaxref1112.html
http://java.sun.com/products/jsp/syntax/1.1/syntaxref117.html#8772

This is also an excellent jsp syntax ref you can print out.
http://java.sun.com/products/jsp/syntax/1.2/card12.pdf

If I understand you correctly you want your 'do it again' button to clear
all of the output on the page. You can do that by submitting to the Servlet
& clearing the variables. If they are request scope anyway, just returning
the page will have cleared the variables.

With regard to frames, I agree they can be useful. But they can also be over
used & lead to inelegant solutions. But the fact is they are deprecated & do
cause problems for people with screen readers. I try to avoid them now if
possible & look for other solutions. 99% of the time there are more elegant
ways to achieve the same thing :-)

HTH :-)
Signature

-P
"Programs that are hard to read are hard to modify.
 Programs that have duplicated logic are hard to modify.
 Programs with complex conditional logic are hard to modify"

( Kent Beck)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.