• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using beans with my jsp

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tottally changed my approach for this jsp/servlet project, and i am now using beans and the MVC architecture. SO i am trying to login a user when they enter their username and password, and click login. My main class, which acts as my controller, is like so


So it basically request the parameters and sets them into my bean, and then forwards it to logUser.jsp. My bean is looking like so

Its the getLogin method in their i need to invoke, but i am having problems in my jsp on how to invoke it through a bean. This is my jsp as far



So i request the bean in this jsp, but then how would i invoke the getLogin method in my bean class, with the two current set variables (userName, passWord) of the bean?
any advise would save a life (atleast my poetry is getting better)
cheers
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you delaying work until it gets to the JSP? You already have a page controller (research better naming than "main", and what's with the messy "mywork" stuff?) -- your work should be done there. The JSP should be to construct the view only.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was thinking to change the names of my files, will do that. You say that a jsp is just to construct a view, and i can understand that for what i am doing at the moment. But the reason i am working with beans is because afterwards i will be doing searches in my database and outputting the results to the jsp to be displayed in a table. This means that surely i would have to mix jsp with my java beans?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it does not. All work should be done in controllers and the results passed (in beans or other constructs) to the JSP as read-only data.

All data processing should be completed before the JSP is invoked.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in regards to this, i am trying to add somthing like this to my controller to log someone in


The problem then is, 2 will always be returned as i am using the bean to set the username and password for a specific person, but then i am just calling up the getLogin method through an instance, which doesnt relate to whats been inserted as the username and login. I would be better off just doing somthing like
String username = request.getParameter("userName")); and then pass these variables to the method. I was just thinking it might be better to use beans.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code is using 1 and 2 to indicate results? Why not a boolean? "Magic numbers" are always going to cause trouble at one point or another.

Beans are useful for gathering data into a single convenient package. Don;t use them just because you can, but when it makes sense to.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nick Price: you are familiar with this? http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic