Solved

Q for Ken/Object

Posted on 2004-03-24
9
221 Views
Last Modified: 2010-04-01
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
Comment
Question by:wjh7554
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 7

Accepted Solution

by:
searlas earned 195 total points
ID: 10675376
<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
 

Author Comment

by:wjh7554
ID: 10676297
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
 
LVL 7

Expert Comment

by:searlas
ID: 10676973
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:kennethxu
ID: 10678130
searlas is right!
0
 

Author Comment

by:wjh7554
ID: 10686616
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
 
LVL 7

Expert Comment

by:searlas
ID: 10688381
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 10689486
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 10689496
Security rule: never trust what client send to you.
0
 

Author Comment

by:wjh7554
ID: 10693520
Thank You guys.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question