Solved

Q for Ken/Object

Posted on 2004-03-24
9
220 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
  • 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
Industry Leaders: 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
J2SE 5.0 metadata 1 67
some methods private some are not 8 221
iterator example remove 8 75
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 698
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
5 Ways to automate alert management in ConnectWise // The art of alerting is in automation. When humans are removed from the alerting process, errors are fewer and action is almost immediate. But how do you automate the alerting process and what …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

679 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