Some weeks ago, there is a discussion on Model2 architecture, with some
people like Craig. very useful ! thanks a lot !
I have tried something very useful, and prettiest I had used to see on
tutorials, or atricles on this subject.
My solution is based on the use of javascript instruction and the "onClick"
attribute, all these will act on a HIDDEN value called actionType, because
this is this value which is used by the controller servlet.
example:
part of the JSP file
...
<FORM METHOD="POST" ACTION="/servlet/ControllerServlet" >
<INPUT TYPE="HIDDEN" NAME="actionType">
<INPUT TYPE="TEXT" NAME="lastname" VALUE="Compagnon">
<INPUT TYPE="TEXT" NAME="firstname" VALUE="Guillaume">
<INPUT TYPE="TEXT" NAME="email" VALUE="[EMAIL PROTECTED]">
...
<INPUT TYPE="SUBMIT" VALUE=" send an email " NAME="button1"
ONCLICK="this.form.actionType.value='sendEMail'; return true;" >
<INPUT TYPE="SUBMIT" VALUE=" save the profile" NAME="button2"
ONCLICK="this.form.actionType.value='saveProfile'; return true;" >
...
<INPUT TYPE="SUBMIT" VALUE=" do some stuff " NAME="button33"
ONCLICK="this.form.actionType.value='doStuff'; return true;" >
</FORM>
SO it 's easy in the controller servlet
in the doPost method
String what = request.getParameter("actionType");
if( what.equals("sendEMail") ) {
// use JavaMail API
}
else if( what.equals("saveProfile") ) {
// use JDBC API in order to connect a DBMS
saveProfile(request,response)
}
...
else if( what.equals("doStuff") ) {
doStuff( request, response );
}
Have fun with MVC pattern.
Guillaume Compagnon
[EMAIL PROTECTED]
personal: [EMAIL PROTECTED]
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets