• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not getting what this servlet is doing+MVC

 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends I downloaded MVC(model2) based program from coreservlets website and I was unable to understand the servlet code mainly this code

My questions is that when the user entered respective id in this form (which is View) and here He is entering ID number from that how the servlet identifies the bean and view with respect to the user ID

Here is Bean Code

thanks in advance
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what the problem is. It retrieves the customer by the customer ID, puts the customer into scope, and displays a JSP.
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply and you are right by using customer ID it retrives data rite and what this code is doing

can you tell me exactly
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's returning the customer by ID.
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay and here is the code and sorry for not posting the code what it is doing BankCustomer customer = BankCustomer.getCustomer(request.getParameter("id"));
ShowBalance.java

BankCustomer.java

index.jsp

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you had posted the code, I just didn't see it in the original unformatted version.Is this the code you're asking about? I mean, there's not much to it.
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ofcourse and i mentioned a simple cod e in Bold and again i am posting that code
piece of code from ShowBalance.java
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you're asking what that code is doing?
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh.

It's calling the static method getCustomer(String) from the BankCustomer class, passing in the ID request parameter. The getCustomer method looks up the customer in the map and returns it if the customer exists, or null if it doesn't--just like the Javadocs included in the code you posted says it does.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11941
211
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by looking at this HTML snippet from the index.jsp file:

When the user is looking at this page in their browser, they will see the text "Customer ID:" along with a box where they can enter the customer ID. That box has the name "id".

When the user hits the submit button, they will be sent to the "showBalance" page (because the form states that action="./show-balance") with the "id" tacked on the end of the URL. So if you entered "abcd" into that text box and hit enter, then the URL will look like show-balance?id=abcd

Once that hits your servlet, it needs to retrieve the customer id, which is what it does with the snippet request.getParameter("id").
 
Vas Miriyala
Ranch Hand
Posts: 114
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome explanation David ,andrew thanks a lot and one small doubt that is What is meant by Page-centric?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic