• 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

Forms

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would you normally do form submission?
Using a jsp pass to jsp for processing?
Using jsp to servlet?
Using servlet?
Also, is there a command for jsp like in php where i can do
--------------------------------------------
if(isset($submit))
runProcessing();
endif
--------------------------------------------
So that i can process the forms information on the same page?
Thanks everyone
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is a "jsp pass to jsp"
This is not a sports forum!
Ha ha! That last paragraph was a joke!
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand the question but I'll pretend that I do
A form is submitted to a JSP like this:
<FORM ACTION="myJSP.jsp" METHOD="post">
<INPUT TYPE="Text" NAME="username">
<INPUT TYPE="Submit">
</FORM>
I personally don't like the idea of FORMs submitting to JSPs directly but instead I prefer that an ACTION in a FORM points to a (controller) Servlet. And then this servlet would forward to a JSP (view).
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to use the same jsp for the form and also for the form processing you can do something like:
let's say you specified POST in your action, then you would say...
if(request.getMethod().equals("POST") {
// do all your processing here provided you have initialised some global variables at the top
do validation
insert into db or some other stuff
} // end main processing
I use this technique a lot because I normally just want one file instead of two say for login.
One last thing: in this case the you set the action to the name of this jsp since it is also being used for processing its own form!!

[This message has been edited by ernest fakudze (edited August 29, 2001).]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony - I've heard that Struts in Jakarta helps implement what you've described. Have you worked with it at all?
Joe

Originally posted by Tony Alicea:
I don't understand the question but I'll pretend that I do
A form is submitted to a JSP like this:
<FORM ACTION="myJSP.jsp" METHOD="post">
<INPUT TYPE="Text" NAME="username">
<INPUT TYPE="Submit">
</FORM>
I personally don't like the idea of FORMs submitting to JSPs directly but instead I prefer that an ACTION in a FORM points to a ([b]controller
) Servlet. And then this servlet would forward to a JSP (view).[/B]


 
Ryan Yeap
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony Alicea
-----------------------------------------------------------------

What is a "jsp pass to jsp"
This is not a sports forum!


LoL. Okie , Maybe I should have made it clearer

I personally don't like the idea of FORMs submitting to JSPs directly but instead I prefer that an ACTION in a FORM points to a (controller) Servlet. And then this servlet would forward to a JSP (view).


Yeah , this was basically the answer i was looking for . I need to ask one thing though, would this method be preferred if I am doing a list from a database? (ie select * from database). Or would jsp pass jsp be better? (read below)
ernest fakudze
-----------------------------------------------------------

If you want to use the same jsp for the form and also for the form processing you can do something like:
let's say you specified POST in your action, then you would say...
if(request.getMethod().equals("POST") {
// do all your processing here provided you have initialised some global variables at the top
do validation
insert into db or some other stuff
} // end main processing
I use this technique a lot because I normally just want one file instead of two say for login.
One last thing: in this case the you set the action to the name of this jsp since it is also being used for processing its own form!!


This was what i was asking when I meant jsp pass jsp One thing though, is there a way to check weather a certain button has been pressed? Say , my page has 2 diff buttons.
index.jsp
----------------------------
<form action="index.jsp">
<input type="text" name="title">
<input type="submit" name="submit_title">
</form>
<form action="index.jsp">
<input type="text" name="number">
<input type="submit" name="submit_number">
</form>
-----------------------------------------------------
would
if(request.getMethod().equals("submit_title") {}
elseif(request.getMethod().equals("submit_number"){}
work?
Thanks a lot guys
[This message has been edited by Ryan Yeap (edited August 29, 2001).]
 
Ryan Yeap
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*bump*
 
ernest fakudze
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah Ryan, it would still work even if you had 20 buttons: here is what I do:
at the top I declare a gloabl variable called...
String buttonPressed = "";
then below I do..
if(req.getPram("cancelButton") != null) {
buttonPressed = "Cancel";
} else if (req.getparam("saveButton") != null) {
buttonPressd = "save";
} else if req.getparam("Delete") != null){
...
} end
// Now you know which btn was pressed and you don't have to worry anymore!!
Remember that you can say..
out.println(buttonPressed); to see it's value if you are not sure of what is happening - a good debugging technique!!

Then you can continue to do your actions below after you have decided which buttn was pressed. Cool hey?
This is not right though...
if(request.getMethod().equals("submit_title") {}
elseif(request.getMethod().equals("submit_number"){}

here is what to do..
if(request.getMethod().equals("POST")) {
if(buttonPressed.equals("Save")) {
//more error checking here
} else if(btnPressd.equals("Delete")) {
}..and so on
} // end if request.getMethod = post
I really like to use the same jsp for both the form and handling because it reduces clutter of files, so I have 1 file instead of two. It also prevents you from taking your user to another page to tell them that there is an error if there is one. Using 1 file means you can output the error message right below the form or on top depending of which one you prefer.
REMEMBER - YOU SHOULD HAVE 1 FORM IN YOUR JSP PAGE IF YOU WANT TO USE THIS METHOD OF FORM PROCESSING!! I'm sure you can have more than 1 but nobody does that!! LOL!
Try it. I don't know if it has speed implications though as compared to using a controller (servlet) for form handling.


[This message has been edited by ernest fakudze (edited August 31, 2001).]
 
Ryan Yeap
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! I'll give it a shot now.
 
A timing clock, fuse wire, high explosives and a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic