Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my jsp page.. I am getting the method from modal class and iterating the table..

HTML
<html>
<body>
<%ArrayList<Employee> empList=new ArrayList<Employee>();
ModalClass emp=new ModalClass();

empList = emp.getEmployess();

<!-- With this list i will iterate my table -->

</body>
</html>



And this is my modal class(java), is used to fetch the values from db.

Java
public Class ModalClass {

public ArrayList<Employee> getEmployess(){
    //In this method i am fetching the db values and storing into the List and returning the list...
 

return list;
}




I hope the reader can understand my coding,now my question is Wheather my code follows MVC pattern..

Thanks in advance...
Posted

 
Share this answer
 
Comments
srkrishnan0509 14-Feb-14 8:16am    
I am using web module 2.3 in eclipse so i couldt integrate JSTL.. wat shall i do?
thatraja 14-Feb-14 9:57am    
I'm not a java guy but gave you things using Google. Surely you could find a lot there. Happy weekend
srkrishnan0509 15-Feb-14 3:20am    
ok any way thanks dude
I am not too sure whether your code follows MVC pattern

In MVC

1.Model : Model is where the data classes, looks you have done this using the class "ModalClass"

2 View : This should be almost pure HTML and should not have any data access class initiations / methods and you are defeating this by using the following

XML
<%ArrayList<Employee> empList=new ArrayList<Employee>();
ModalClass emp=new ModalClass();

empList = emp.getEmployess();

<!-- With this list i will iterate my table


3. Controller : This is where you will have any data access class initiations / methods and its missing in your case.

I think you code does not satisfy the MVC pattern
 
Share this answer
 
Comments
srkrishnan0509 14-Feb-14 8:15am    
Thanks dude, but i have one doubt i have to call the method when jsp page loads, so i need to use java code to call that method..is there any other way to call the method in mvc pattern?
Bala Selvanayagam 14-Feb-14 8:18am    
Hi, I am not sure about how the java side works.

In Microsoft .net side, "Controller" is responsible for calling the methods (not the html layer) and it will pass the result to the view (HTML) and the view will render the data.

In other words, the so called "method callings" are separated and put under controller and from controller the result (object) is passed to the view
Bala Selvanayagam 14-Feb-14 8:19am    
Your code

<%ArrayList<employee> empList=new ArrayList<employee>();
ModalClass emp=new ModalClass();

empList = emp.getEmployess();

<!-- With this list i will iterate my table

should have been under the controller
srkrishnan0509 15-Feb-14 3:21am    
ya i got it thanks yaar
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900