Forums Register Login

Using beans with my jsp

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Destroy anything that stands in your way. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1364 times.
Similar Threads
Cookies in servlet
Forwarding data to jsp from servlet
Jsp Login Page Problem
java.lang.NoSuchMethodError
accessing beans in servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:23:47.