• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

A question regardin JSP...

Hi, I will like to get some help in understanding some JSP consepts. I am a lillte confused regarding the MVC architechture. I understand how to create
JSP pages, servlets, bean file, and WEB.xml file, but I am not able to understand how all these modules work to gether.I have created some small apps that
 have a JSP page and a bean file I have also created some apps that work with the JSP page and a servelet. My question is how / why do we use a servlet and
a bean file ( I realize that the servlet is some kind of controller) and the WEB.xml file? For example, let me assume I am creating a small application to calculate the employee payrolls. I have full time and part time employees. My site design will be as follows;

1. JSP page to enter the employee name/other details and also a field that will indicate it the employee is full time or part time.
2. On the same JSP page I will have a field that will show the number of hours worked,and if the employee is  a full time employee there is a standard pay
and if the employee is a part time  the pay is calculated on an hourly basis. Overtime will be (above 40 hrs a week) will be have to be doulbe the pay.The calculated pay will need to be stored in a DB.
3. The hourly pay rate is stored in a database. ( that value will be entered in through another form on the application.). And depending on the full time employee code the pay will be different.
4. I will need to have a db connection file.
5. I will need to see the monthly payroll report.

Now, my quesion is when I design this application:

1) Which is going to be my bean file
2)which is going to be my servlet
3) what will my web.xml file contain

I really do not need the code for the application, but just the logic to bring this whole thing together. Thank you for your help.

A
0
aej1973
Asked:
aej1973
  • 2
  • 2
1 Solution
 
mohammedfCommented:
1. ur bean will be the employee information ( name , hour working ,full time employee there is a standard pay and all these things )
2. u will make too a database connection class ( it will be like bean ) all database work ( connecton and queries ) will be inside this class ( it is separated class than employee bean)
3. in ur servlet u will use these two beans ,  ( u will use connection bean to deal with database , and u will use the employee bean to get and retrieve values with database)
4. u will use web.xml to register ur servlet ( its name , URL patter "how u can access this servlet)"
u will make an HTML page to make this communication
0
 
aej1973Author Commented:
1. ur bean will be the employee information ( name , hour working ,full time employee there is a standard pay and all these things ) : OK
2. u will make too a database connection class ( it will be like bean ) all database work ( connecton and queries ) will be inside this class ( it is separated class than employee bean)
3. in ur servlet u will use these two beans ,  ( u will use connection bean to deal with database , and u will use the employee bean to get and retrieve values with database)
4. u will use web.xml to register ur servlet ( its name , URL patter "how u can access this servlet)"
u will make an HTML page to make this communication: Can you explain what do you mean by 'how u can access this servlet' ?

So from what I understand;
1)The mysql queries will reside inside the bean. The bean is going to be my java file where I will intialize all the paramenters
2) I will have a seperate class for the DB connection
3) What does the servlet do? Why do I need to use the servlet?

Thank you for getting back to me.

A
0
 
mohammedfCommented:
>>1)The mysql queries will reside inside the bean. The bean is going to be my java file where I will intialize    >>all the parameters
Yes ... this is true

>>2) I will have a separate class for the DB connection
Yes ,,, and it will be in the same previous bean ( Queries + connection for DB)

the servlet will be to handle client request ( which will be via HTTP requests ,, which means the client will use a browser )
ie: u have a form that the user will enter the information about ur employee ( name , hours and so on ) this will be as an HTML form ,and the action of this form will be the SERVLET ,, so the servlet will receive these parameters , make connection ( using ur bean ) and store these values in the database ( using quires in the same bean)
0
 
aej1973Author Commented:
Thank you. This is good.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now