Link to home
Start Free TrialLog in
Avatar of linda22
linda22

asked on

Use of Java beans

My ques is a very basic one.
What is the use of beans in JSP.
If I make a form in html and submit it to a jsp page where I receive it  using

request.getParameter("var1");

and insert it into the database.
The other method is to send it to a bean using
      <jsp:setProperty name="TheBean" property="*" />

Which method is better and why.
The same thing i'd like to know when retreiving data.
I retreive the data in jsp page and display it in HTML table

<TD><%=rs.getString("col1")%></TD>

The second method could be to retreive the data in the bean and concatenate it to a variable

      showData=showData+"<td>";
            showData=showData+col1;
            showData=showData+"</td>";
And then fetch the variable in the JSP page and print it there.
Which method of the 2 is better. Moreover when I use the method of beans to retreive data it makes the application very slow. What could be the reason for that?
Kindly Suggest
          
SOLUTION
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of linda22
linda22

ASKER

Thanks everyone for  suggestions.
Another thing i want to know. What sort of code should be placed in the JSP page?
Should it be only calls to methods in java beans and some HTML or something else?
Can there be any situation when make making a connection and performimg DML or select operations be done in the JSP page or they should always be done in the bean.
Avatar of linda22

ASKER

Points increased to 240 from 190
>>What sort of code should be placed in the JSP page?
Normally, i will put iteration or looping code in the JSP, for example :

<%
   for( int i = 0 ; i < thisList.size(); i ++ )
   {
%>
<html tag>
<%
  }
%>

>>Can there be any situation when make making a connection and performimg DML or select operations be done in the JSP page or they should always be done in the bean.

Basically, In MVC model, JSP page plays the Viewer role, and the logic should be seperated in the java beans.
Avatar of linda22

ASKER

Thank You so much