?
Solved

which is better

Posted on 2006-05-02
36
Medium Priority
?
259 Views
Last Modified: 2013-11-24
suppose i want to design login page.

waht i have to implement in model class

is it simple java bean class or java with jdbc or java with entity bean

could you tell me which is better
0
Comment
  • 13
  • 11
  • 9
  • +1
36 Comments
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16583837
I think java with jdbc  will be better.

but tell us what kind of application is it and what ru trying to do.

Thank You.
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16583843
but tell us what kind of application is it and what ru trying to do.

Hippa-- Helathcare product
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16583852
so what you want to do in the login page checking for valid user???
or anything else?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Accepted Solution

by:
Giant2 earned 200 total points
ID: 16584070
In the model class you must specify the methods you want to use to check your usename/password.
The connection (jdbc, etc.) to resources must be displayed in othe model.

Bye, Giant.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16584096
I think you could use a session bean to implement the logic, and make it talk to any data-store (keep it configurable in a configuration/ properties-file). You should be able to choose between any data-source like JDBC, web-service, LDAP, XML, etc (the authentication credentials can be stored anywhere and JDBC is not mandatory).
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584125
so what you want to do in the login page checking for valid user???
yes, and view the particular customer account details
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16584144
>> so what you want to do in the login page checking for valid user???

Send a request to a Servlet with user-name/ password. Servlet will get them using getParameter () and send the values to a session bean. The session bean will contact whatever data-store (abstracted/ interfaced) and get the results, then send back to the servlet. The servlet will decide, based on the result which JSP it should forward the info to.
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584172
>>The session bean will contact whatever data-store (abstracted/ interfaced) and get the results,

could you explain with simple code.

session bean means ,is it stateful sessionbean?.

session bean program connected with database, and retrieve the values, and view through jsp.

is it correct?

0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584181
>session bean means ,is it stateful sessionbean?.
In the solution provided by mayankeagle it is so.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16584232
Actually it can be stateless also.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16584237
And BTW, it is not mandatory to use an EJB there. You can also use a local business logic layer which the servlet uses.
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16584379
Simple thing is to just create a servlet and pass the parameters (user name and pwd) from the login page to the servlet let the servlet hit the databasde and check the validations and then let it collect the required data and the use a request dispatcher to get the response on to JSP.
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584413
database connection and database coding is there in java/jdbc

suppose i have user class in model it contains database connection and coding.

so i create a user class object in servlet i retrieve the data from database
how could i collect user name and password in servlet class. and pass them in to request dispatcher and view through jsp
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584424
>collect user name and password in servlet class
using request object:
req.getParameter(...)
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584427
mayankeagle told you before:
>Servlet will get them using getParameter ()
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584435
mayankeagle told you before:

yes

my question is

how could i collect username and password from java/jdbc class into servlet class
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584442
HTMLPage send a request (POST) to the servlet XXX
XXX servlet in the doPost method takes te two parameters from the request. After this, it does a simply query on your database like "SELECT * from Users WHERE username=..... AND password=......". If this answer correctly one record, ... and so on.
Where is your problem?
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584461
>>SELECT * from Users WHERE username=..... AND password=...


after this i have username and password variable in user class.

how could i pass into servlet class and view through jsp textboxes

how could i pass that variables into requestdispatcher.forward
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584472
If you use a "user class" you can ask them to it using (creating) get methods.
To forward you can do something like:

req.setAttribute("theDataBean", yourDataBeanORyourUserClass);
RequestDispatcher rd = getServletContext().getRequestDispatcher("your jsp page name.jsp");
rd.forward(req, res);
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584501
i want to create get and set mehtods in smple javabean user class , that connect to database

is it correct?
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584519
yep!
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584527
Something like:
setUserName(String username)
setPassword(String password)
boolean checkUserPass()
getUserName()
getPassword()
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584536
where i mention database connection coding in userjavabean class
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584551
the database resource is not externally visible (no other process must be use it).
So you can initialize/get the connection and use it in the checkUserPass() method.

Even you can pass it from the main servlet itself using a setter method before calling the checkUserPass() method.
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584570
well

how could i collect username and password from userjavabean class into servlet.

and pass it to simple jsp

i dont know how to pass username and password into requestdispatcher method

coud you explain with simple code

0
 
LVL 12

Expert Comment

by:Giant2
ID: 16584576
I told you before!
If yourDataBean is the name of your dataBean class:
>public void doPost(...){
>...
>req.setAttribute("theDataBean", yourDataBeanORyourUserClass);
>RequestDispatcher rd = getServletContext().getRequestDispatcher("your jsp page name.jsp");
>rd.forward(req, res);
>}

In this manner you send a forward to the jsp you need passing to it the dataBean.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16584859
Remember not to write any DB connection code in the servlet - don't tie the servlet to the data-store implementation. Tomorrow, it could be stored in XML files instead of a DB.
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584878
>>Tomorrow, it could be stored in XML files instead of a DB.

at what purpose
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16584908
in jsp page i have to use

<JSP:USEBEAN ID =USERbean>  an acceess that variable in that class

is it correct.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16584948
>> at what purpose

Your data store could be anything, depending on the organization where you deploy your application. It need not be a database always.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16585005
You must have:
<jsp:useBean id="theDataBean" class="theFullName of the class of your bean" scope="request">
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16587130
if i am not using javabean class, i am using normal java/jdbc coneection class

that would return username and password.

how could i collect username and password from java/jdbc class

and view through jsp
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 200 total points
ID: 16587325
I would probably use:

public interface DataStore
{
  public UserInfo getUserInfo ( String userName ) ; // UserInfo is a class holding user information
}

Now give various implementations for this:

public class FileStore implements DataStore
{
  public UserInfo getUserInfo ( String userName )
  {
    // get the details from the file
  }
}

public class DatabaseStore implements DataStore
{
  public UserInfo getUserInfo ( String userName )
  {
    // get the details from the data-base
  }
}

Keep an interface reference at the code which has the business-logic (servlet or session-bean). Read the implementing class-name from a properties/ configuration-file and instantiate an object using:

DataStore store = ( DataStore ) Class.forName ( classNameFromConfig ).newInstance () ;

Invoke its methods and get the result in the business-logic layer (so it is completely interfaced/ abstracted out from data-base or data-store related stuff). Then decide whether you need to send it to another page and what message needs to be sent.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16587356
For a data-base/ JDBC implementation, you need to shoot a query and populate the object, like:

public UserInfo getUserInfo ( String userName )
{
  UserInfo obj = null ;
  // shoot a query to get the user-info
  if ( rs.next () )
  {
    obj = new UserInfo () ;
    obj.setUserName ( /* value from DB */ ) ;
    obj.setPassword ( /* value from DB */ ) ;
  }
  return obj ;
}

For JDBC details, look at http://java.sun.com/docs/books/tutorial/jdbc/
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 16591847
How could i collect userinfo object into servlet
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16593427
>> DataStore store = ( DataStore ) Class.forName ( classNameFromConfig ).newInstance () ;

Then you could do:

UserInfo info = store.getUserInfo ( request.getParameter ( "username" ) ) ;
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 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