Newbie,
Im trying to add an actionListener ActionEvent to a submit button in
jsp and don't know how to go about it.
<form name="form" method="post" action=""
enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit">
<%
Submit.addActionListener(this);
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Submit )
{
//code to copy image
}
}
%>
</form>
Thanks.
Bjorn Abelli - 30 Mar 2006 17:08 GMT
> Newbie,
I understand that you're a newbie, as you have missed an important
difference between JSP and "plain" applications.
> Im trying to add an actionListener ActionEvent to a submit button in
> jsp and don't know how to go about it.
JSP renders HTML-pages to be sent to the browser on the client side, and
responds to requests done to the server. This makes it impossible to add any
meaningful Java-code to be executed on the client-side.
What you usually do, is simply to respond to the submitted request. This
could e.g. be another page, or the same page:
<form method="post" action="somePage.jsp">
...and then in somePage.jsp, handle any parameters you've recieved.
String what = request.getParameter( "literal string of field name");
if ( what.equals("something") ) {
// Do whatever...
}
// Bjorn A
-------------
Get FREE newsgroup access from http://www.cheap56k.com
Chris Smith - 31 Mar 2006 17:46 GMT
> Im trying to add an actionListener ActionEvent to a submit button in
> jsp and don't know how to go about it.
[quoted text clipped - 15 lines]
> %>
> </form>
JSP is not AWT, and you can't use the same techniques as you may be
accustomed to using in AWT. There are a few things that you might want
to do:
1. If JavaScript is sufficient to do what you want, you can add a
JavaScript handler for the "onclick" event. This is outside the scope
of Java, and is better discussed in comp.lang.javascript.
2. You can fill in the "action" attribute of your form with some URI
that maps to a servlet. Whatever code you wanted to write in
actionPerformed, you should then write in the servlet's doPost method
instead.
3. If you really like the event/listener kind of organization, you can
look into JavaServer Faces (JSF). Then you actually could add something
called an ActionListener to the button (though it would be a button
declared with <h:commandButton> instead of <input type="submit">) and
write a listener class that handles things.
The main point, though, would have to be that web applications are a
very different environment from client-side apps, and you just can't
expect programming ideas from one to translate cleanly into the other.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation