So glad to find this forum...
I am totally new to servlets and JSP and started to learn from the Head First series a few days ago.
But my teacher gave an assignment in JSP which I have no clue how to do.
Can anyone please help me out??
The assignment is this...
A JSP code to create Employee details with the following fields :
It should also have options to Add and Modify.
And once the form is filled and saved, a page containing the details of all employees including the newly added one must be displayed.
I am supposed to store it in a database and also be able to retrieve it.
I guess some of you might laugh at me as this appears simple... but I'm a total fresher at this stuff... I need your help people!!
Hi Rebecca, it is simple, I will be explaining you how to do that.
step 1: code a html page which asks the user to enter his or details.
step 2: write a servlet which implements the doGet() or doPost() method based on the method you used in the html form. note: if you use post method in your html form and implement doGet() method in the servlet then you will get an error. So be cautious.
step 3: In the controller get the values sent from the html page. Now you have to create a model which actually stores the data in the database.
step 4: the controller is responsible for calling the model, the controller passes the values received from the html page to the model. the model saves the data.
step 5: the model is responsible for connecting to the database.
step 6: after the model executes successfully, now you have to call a jsp page from the controller to display the data you have stored in the database.
step 7: save the sevlet class file in WEB-INF classes folder.
step 8: In the deployment descriptor map the servlet and html page.
anusha chaitanya wrote:I ll try my level best to help others.
I like your attitude!
Thank you sir.
Joined: Dec 25, 2009
I finished the first part of the assignment... the add option... thanks guys
Your answers helped a lot. But I still need to do a lot of work and add a 2 more options - Modify and Delete. I did that to some extent, but its not working!
I will paste my code here. please tell me where the error might be...
I have taken a seperate servletfor deleting called DeleteDb.
I have placed a 'Delete' button in the jsp page which is used to retrieve the table from the database.
In the jsp page, I have added checkboxes and have placed a delete button such that upon clicking, it goes to the DeleteDB servlet :
Here is the DeleteDB servlet code :
please point out what might have gone wrong. Also, what all changes shoyld I make to this code in order to implement 'Modify' option...
And the 'else' part is displaying once i click on the 'Delete' button... i mean, "Error while deleting" is being displayed.
since you are dispatching the request to the next page you are unable to see the "Error while deleting" statement
Joined: Dec 25, 2009
anusha chaitanya wrote:And one more thing is I think you are selecting multiple checkboxes and clicking the delete button. If I am right, then for that kind of job this logic is not correct. Use this one.
I tried this... now i'm getting "java.lang.NullPointerException " once i click on the delete button