Re: Add an actionListener ActionEvent in jsp



lynch_susan <lynch_susan@xxxxxxxx> wrote:
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>

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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.


Quantcast