[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Q for Ken/Object

I have this JSP page contain 10 (for example) input text field.

If i want to set all this 10 elements into my javabean, i need to do javabean.setField1([value_of_field1]); for 10 times.

I wonder is there a way to ease this way of doing things?
0
wjh7554
Asked:
wjh7554
  • 3
  • 3
  • 3
1 Solution
 
searlasCommented:
<jsp:useBean id="javabean" scope="session" class="com.foo.YourJavaBeanClass" />
<jsp:setProperty name="javabean" property="*" />

See:
http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html#8865
and
http://java.sun.com/products/jsp/tags/11/syntaxref11.fm13.html
0
 
wjh7554Author Commented:
searlas, tq for you suggestion. But that's not my question is all about.

My issues here is when i have 10 input type="text" name="[different name]" />
i need to setProperty for 10 time into the bean or something else.

I wonder is there any method or way to ease this kind of un-productive way.

like your second link, setProperty mean will insert(or set the property) one by one into a bean.

TQ.
0
 
searlasCommented:
Read again:
<jsp:setProperty name="javabean" property="*" />

The important bit is property="*", that's litereally a *, that's not a place holder for any names.  By putting a * the container will call each and every method.
e.g. if calling a page as:
your.jsp?field1=jobby&second=bob&field4=whatever

The code that would be executed would be equivalent to:
javabean.setField1("jobby");
javabean.setSecond("bob");
javabean.setField4("whatever");

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
kennethxuCommented:
searlas is right!
0
 
wjh7554Author Commented:
is there a security issues??
i come across this in most of the book and they are not recommanding this.

Anyway, actually i have a idea on doing this. But not sure is it workable or not.
I plan to create an interface and my own API on handling this. Some sort like making my database as a object-oriented. Everytime i run the command (some java program), it'll use the java.sql.getMetatype etc to read the table schema. Then it'll generate few files for me.

Those file will contain those set, get for me.

What i will do in my JSP page is i will create the object for those files that i created. Then it'll use one statement,
ObjectA oa = New ObjectA();
oa(request);

then it'll automatically set the whole input type into my object. From there i move on to my SQL ..

..

Is this idea workable?
0
 
searlasCommented:
The security issue is most likely not an issue; you just need to be aware that by tampering with the URL, a malicious user would be able to call any of the set methods.

For instance, if a bank used jsp:setProperty then a malicious user may find it useful to edit the url to:
blah.jsp?balance=1000000.0

The parameter would be automatically converted (if necessary) into a number, and the method setBalance() called.  Note, this issue also arises for applications using struts.  It's just something to be aware of.

I don't see the point in reinventing the wheel, so I'd use jsp:setProperty as is.
0
 
kennethxuCommented:
again searlas is right on this. the issue is rather programming issue. I have seen a lot of web app use javascript for data validation, that if fine but if you solely depend on client side validation, your application is designed to be attacked. My advise to everybody is: server side validation is must and client side is optional.

in addition, you need to be aware that the setxxx menthod will not be called if the field is blank.
0
 
kennethxuCommented:
Security rule: never trust what client send to you.
0
 
wjh7554Author Commented:
Thank You guys.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now