File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is "action" a reserved word?" Watch "Is "action" a reserved word?" New topic

Is "action" a reserved word?

Chris Skinner

Joined: Jan 23, 2002
Posts: 23
I just had a strange problem with a struts app I'm working on. I have a field in my form bean :

private String action;

with the appropriate getters and setters.

In my .jsp I am using it like such :

<html:select property="action">

Anyway, when I submit the form I get an internet explorer script error saying the object does not support this property or method.

I changed the name of the variable to action1 and I no longer get the error. So I'm curious is "action" actually a reserved word in struts that I'm unaware of? Anybody else ever seen this ?


Christopher Skinner<br />SCJP2 1.4<br />SCWCD (in training)
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
Its not a reserved word in struts.
It IS an attribute of an html form.

A lot of time in HTML you will see:

The problem comes in javascript.
myForm.action normally refers to the attribute "action" on the form tag.
Sometimes you want to change this with javascript: eg myForm.action="/"

myForm.userName refers to the textfield on the form.
eg myForm.userName.value = 'John Doe'

But what happens if you put a control called "action" in your form?
Does myForm.action refer to the attribute "action" in the form tag, or the control embedded in the form?
You see how the confusion arises?

Suggested solution: don't use action as the name of a control on a form. I would also avoid "name", "id", "method" or any other attributes of the form tag that you might want to access in javascript.

Chris Skinner

Joined: Jan 23, 2002
Posts: 23
Ah-Haa.....thanks that makes sense.
I agree. Here's the link:
subject: Is "action" a reserved word?
It's not a secret anymore!