Servlets and JSP Forms: A Comprehensive Guide
VerifiedAdded on 2019/09/26
|18
|2498
|332
Report
AI Summary
In the provided assignment content, it is suggested that for a complex project with bidirectional connections between JSP forms and Servlet action classes, grouping all classes into one package according to their type (view-related or controller-related) can make it easier to track each class. Additionally, distributing code work into separate files using JSP files for view sections and Servlet class files for controller sections can help in tracking data flow from one form to another and one class to another. The assignment content also highlights the importance of understanding design patterns such as MVC (Model-View-Controller) and EJB (Enterprise JavaBean).
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Contents
Overview of approach to development and general rational......................................................................1
Detail of design and coding techniques used and reasoning behind their use............................................1
The design/coding techniques:................................................................................................................1
Why I chose this technique:....................................................................................................................1
Evidence:.................................................................................................................................................1
Conclusion:..........................................................................................................................................2
Architecture Model.....................................................................................................................................2
Critical analysis of solution..........................................................................................................................2
Issues:......................................................................................................................................................2
Suggestion:..............................................................................................................................................3
Suggested use of design patterns................................................................................................................3
Jsp/Servlet Pattern with HTML................................................................................................................3
EJB design patterns..................................................................................................................................4
References...................................................................................................................................................6
Overview of approach to development and general rational......................................................................1
Detail of design and coding techniques used and reasoning behind their use............................................1
The design/coding techniques:................................................................................................................1
Why I chose this technique:....................................................................................................................1
Evidence:.................................................................................................................................................1
Conclusion:..........................................................................................................................................2
Architecture Model.....................................................................................................................................2
Critical analysis of solution..........................................................................................................................2
Issues:......................................................................................................................................................2
Suggestion:..............................................................................................................................................3
Suggested use of design patterns................................................................................................................3
Jsp/Servlet Pattern with HTML................................................................................................................3
EJB design patterns..................................................................................................................................4
References...................................................................................................................................................6
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Overview of approach to development and general rational
I have used object oriented approach. . I have used Jsp and servlet technology to develop
this application. I have used MySql as backend database.All forms are separately
designed and their actions are performed by Servlet classes and they are separately
related to different Jsp pages
Detail of design and coding techniques used and reasoning behind their
use
I have used singleton design pattern.
Coding Techniques:
The design/coding techniques: I have followed partial object oriented approach.
Why I chose this technique: My application is not so big and also only I have
designed this whole code. This project is not so big. This has simple and little
functionality to implement so I make this simple by implementing very basic coding
techniques.
Evidence: as you can see in my code there are only two types of file I used and they are
: Jsp and Servlet type. In this project, all Jsp files are located in WEB-INF folder which
represents the web forms where users can interact with my web application. And all
servlet classes are placed in Source Packages’ default packages; here my all servlet
classes are model type these interact with database and perform all actions and direct
contact with Jsp forms by calling them. In my project code there are no controller classes
because my web application is very simple with the little functionalities so all Jsp forms
directly interact with the Servlet classes and all Servlet classes directly interact with Jsp
forms.
For example:
register.jsp form directly interacts with the AddNewUser.java Servlet class
When user fill the all details mentioned in the register.jsp form and click on
register button then form action call will redirect to AddNewUser.java Servlet
class where all parameters are get and then they are saved to database and after
this the call is redirect to index.jsp where user can login and can go further related
pages.
When user click on the login button then other login.jsp page is called and the
user will be identified in this page and then call will be redirect to that page which
I have used object oriented approach. . I have used Jsp and servlet technology to develop
this application. I have used MySql as backend database.All forms are separately
designed and their actions are performed by Servlet classes and they are separately
related to different Jsp pages
Detail of design and coding techniques used and reasoning behind their
use
I have used singleton design pattern.
Coding Techniques:
The design/coding techniques: I have followed partial object oriented approach.
Why I chose this technique: My application is not so big and also only I have
designed this whole code. This project is not so big. This has simple and little
functionality to implement so I make this simple by implementing very basic coding
techniques.
Evidence: as you can see in my code there are only two types of file I used and they are
: Jsp and Servlet type. In this project, all Jsp files are located in WEB-INF folder which
represents the web forms where users can interact with my web application. And all
servlet classes are placed in Source Packages’ default packages; here my all servlet
classes are model type these interact with database and perform all actions and direct
contact with Jsp forms by calling them. In my project code there are no controller classes
because my web application is very simple with the little functionalities so all Jsp forms
directly interact with the Servlet classes and all Servlet classes directly interact with Jsp
forms.
For example:
register.jsp form directly interacts with the AddNewUser.java Servlet class
When user fill the all details mentioned in the register.jsp form and click on
register button then form action call will redirect to AddNewUser.java Servlet
class where all parameters are get and then they are saved to database and after
this the call is redirect to index.jsp where user can login and can go further related
pages.
When user click on the login button then other login.jsp page is called and the
user will be identified in this page and then call will be redirect to that page which
user belong to, for example if user is admin then admin.jsp page will called or if
user is normal user(customer) then userPanel.jsp will called.
Conclusion: So there is bidirectional relatioin in my view classes and model classes because
there are no controller classes in between them. I followed this architecture because this project
is small and this become easy for me by designing this project in this manner.
Here are code snippets which are specifying which jsp form is linked which servlet class.
1. This is index.jsp page which shows a login page with the register here link.
If there is a new user then he/she go with “Register Here” link and then he/she can
register first
When user click on register here link then he/she will redirect to a different jsp page
that is for user registration.
user is normal user(customer) then userPanel.jsp will called.
Conclusion: So there is bidirectional relatioin in my view classes and model classes because
there are no controller classes in between them. I followed this architecture because this project
is small and this become easy for me by designing this project in this manner.
Here are code snippets which are specifying which jsp form is linked which servlet class.
1. This is index.jsp page which shows a login page with the register here link.
If there is a new user then he/she go with “Register Here” link and then he/she can
register first
When user click on register here link then he/she will redirect to a different jsp page
that is for user registration.
When user clicks on submit button then all the user information will saved by
AddNewUser.java class.
After successful registration the user will move to index.jsp page again where he/she
can login to get in the system or get his/her menu.
AddNewUser.java class.
After successful registration the user will move to index.jsp page again where he/she
can login to get in the system or get his/her menu.
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
2. When user choose to login and click on login button on index.jsp page then login
details are validate using login.jsp page. The code of this page is in the following
code snippet
If user is normal user then he/she will redirect to userPanel.jsp page, if he/she is
admin then user redirect to adminPanel.jsp page.
details are validate using login.jsp page. The code of this page is in the following
code snippet
If user is normal user then he/she will redirect to userPanel.jsp page, if he/she is
admin then user redirect to adminPanel.jsp page.
3. Here is the code for aminPanel
Here are three links
Upload image – if user click on this link the admin will redirect to
addOwnerDtls.jsp page
View Image- this link will redirect the admin to viewImgList.jsp
Logout- this link will redirect to logout.jsp page
4. addOwnerDtls.jsp
Here are three links
Upload image – if user click on this link the admin will redirect to
addOwnerDtls.jsp page
View Image- this link will redirect the admin to viewImgList.jsp
Logout- this link will redirect to logout.jsp page
4. addOwnerDtls.jsp
Here admin will fill the details of item owner personal details and when admin clicks on
next button then these details are saved into database by the
SaveImageOwnerDetailsServlet.java class
Here is the code snippet for this java class
When owner details are successfully saved into database then admin will redirect to
uploadImg.jsp page where admin will add item information and upload the item images
save them one by one for single owner.
5. When user click on add item then this item information is saved by the
uploadFileServlet.java class
If admin click on the go to menu then admin will redirect to his/her menu page.
If admin click on the add new owner details then admin redirect to that addOwnerDtls.jsp
page again where admin can add details for new Owner of the items.
next button then these details are saved into database by the
SaveImageOwnerDetailsServlet.java class
Here is the code snippet for this java class
When owner details are successfully saved into database then admin will redirect to
uploadImg.jsp page where admin will add item information and upload the item images
save them one by one for single owner.
5. When user click on add item then this item information is saved by the
uploadFileServlet.java class
If admin click on the go to menu then admin will redirect to his/her menu page.
If admin click on the add new owner details then admin redirect to that addOwnerDtls.jsp
page again where admin can add details for new Owner of the items.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
6. uploadFileServlet.java
This is the java class which save the image file details and after that redirect the admin to
uploadImg.jsp again so that admin will able to add details for more item for one Owner.
7. viewImgList.jsp
if admin click on the view images then the whole list of images will be shown by this
viwImgList.jsp page.
At the end of the page a link “Go Back to Main Menu” is provided. After seeing the
image details then admin able to go his/her menu after clicking on this link.
This is the java class which save the image file details and after that redirect the admin to
uploadImg.jsp again so that admin will able to add details for more item for one Owner.
7. viewImgList.jsp
if admin click on the view images then the whole list of images will be shown by this
viwImgList.jsp page.
At the end of the page a link “Go Back to Main Menu” is provided. After seeing the
image details then admin able to go his/her menu after clicking on this link.
8. If admin click on logout link then all the session attributes are set to null and main
menu will display to user that is “index.jsp” page.
9. Normal user menu: userPanel.jsp
This is the user menu.
Here users are those persons who took part in item bidding.
If user clicks on “View Current Bidding Item List” then they will redirect to itemList.jsp
page
If user clicks on “View Notification” then they will redirect ot userNotification.jsp page
If user clicks on logout then the all session attributes are set to null that are realted to this
user and home page will display that is index.jsp page.
menu will display to user that is “index.jsp” page.
9. Normal user menu: userPanel.jsp
This is the user menu.
Here users are those persons who took part in item bidding.
If user clicks on “View Current Bidding Item List” then they will redirect to itemList.jsp
page
If user clicks on “View Notification” then they will redirect ot userNotification.jsp page
If user clicks on logout then the all session attributes are set to null that are realted to this
user and home page will display that is index.jsp page.
10. itemList.jsp
If user clicks on “view item list” then user able to view all bid items. At the end of the
page a link “Go Back to Main Menu” is provided for user. If user wants to go back to
his/her menu then user clicks on it.
11. If User wants to his/her notification then this page “userNotification.jsp” page will show
user notification if there any. Here user able to see that either he/she won the bid or loss
the bid and he/she can go for further process like payment and all.
If user clicks on “view item list” then user able to view all bid items. At the end of the
page a link “Go Back to Main Menu” is provided for user. If user wants to go back to
his/her menu then user clicks on it.
11. If User wants to his/her notification then this page “userNotification.jsp” page will show
user notification if there any. Here user able to see that either he/she won the bid or loss
the bid and he/she can go for further process like payment and all.
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Architecture Model
I have designed my code using this architecture model. In my code there are JSP forms some
JSP forms are for user where user interacts with this item auction web application and some
JSP forms are with java embedded code. This embedded code is to get data from the database
directly and save data into database by getting information from the JSP page. There are
some servlet classes for e.g. FileUploadDBServlet.java this class. This servlet class is called
by uploadImg.jsp when user select an image and to upload he/she click the submit button.
Then this servlet class first gets the uploaded file details and then save this file into database.
Here are some jsp files that are only for view purpose and servlet classes deal with the
all database query.
Register.jsp save the details for new user by calling servlet class that is
AddNewUser.java.
uploadImg.jsp is also called uploadFileServlet.java class to save the details. This
class saves all the details into database.
Here are the some .jsp files which are directly deal with the database queries.
viewImageList.jsp directly contact with the database and accessing the details of
image list.
viewImage.jsp is also doing same thing.
viewAnItemBidUserDetails.jsp, userNotification.jsp, ownerDetails.jsp, login.jsp and
itemList.jsp, these jsp forms are also directly dealing with the database quiries
without calling and servlet class. Here is the java code is embedded in the .jsp files.
I have designed my code using this architecture model. In my code there are JSP forms some
JSP forms are for user where user interacts with this item auction web application and some
JSP forms are with java embedded code. This embedded code is to get data from the database
directly and save data into database by getting information from the JSP page. There are
some servlet classes for e.g. FileUploadDBServlet.java this class. This servlet class is called
by uploadImg.jsp when user select an image and to upload he/she click the submit button.
Then this servlet class first gets the uploaded file details and then save this file into database.
Here are some jsp files that are only for view purpose and servlet classes deal with the
all database query.
Register.jsp save the details for new user by calling servlet class that is
AddNewUser.java.
uploadImg.jsp is also called uploadFileServlet.java class to save the details. This
class saves all the details into database.
Here are the some .jsp files which are directly deal with the database queries.
viewImageList.jsp directly contact with the database and accessing the details of
image list.
viewImage.jsp is also doing same thing.
viewAnItemBidUserDetails.jsp, userNotification.jsp, ownerDetails.jsp, login.jsp and
itemList.jsp, these jsp forms are also directly dealing with the database quiries
without calling and servlet class. Here is the java code is embedded in the .jsp files.
Critical analysis of solution
Issues:
a) The currently system is very basic there are different Jsp forms for each
functionality and different Servlet classes for each form. So if in future we have to
add more functionalities in any form or have to designed new form to implement
those functionalities then this should be crucial to manage the functionalities
related forms and classes names because in my project there are separate Servlet
classes for each and every Jsp forms, there could be confusion which form is
related to which Servlet classes.
b) In my code there is bidirectional connection between my Jsp web form and
Servlet action classes. This code become very fizzy or complex to understand the
flow of project in large project
Suggestion:
a) For the first problem I can do one thing I will group all classes in one package
according to their type so that it will become easy to track each and every class
whether it is view related or controller or model related.
b) For the second problem I can distribute my code work in separate files so that it
becomes easy to track data flow from one form to another and one class to
another class, for this I will use jsp file for view section and Servlet class files for
controller section these files will access all input data from the viewed forms and
validate them and then will transfer them to Java Bean class (here Java Bean class
will come under model) these classes will interact with the database; they will
save data into database and fetch data from the database and then send back to
controller classes these are Java Servlet classes and then these classes will output
data to JSP forms to display to user.
Issues:
a) The currently system is very basic there are different Jsp forms for each
functionality and different Servlet classes for each form. So if in future we have to
add more functionalities in any form or have to designed new form to implement
those functionalities then this should be crucial to manage the functionalities
related forms and classes names because in my project there are separate Servlet
classes for each and every Jsp forms, there could be confusion which form is
related to which Servlet classes.
b) In my code there is bidirectional connection between my Jsp web form and
Servlet action classes. This code become very fizzy or complex to understand the
flow of project in large project
Suggestion:
a) For the first problem I can do one thing I will group all classes in one package
according to their type so that it will become easy to track each and every class
whether it is view related or controller or model related.
b) For the second problem I can distribute my code work in separate files so that it
becomes easy to track data flow from one form to another and one class to
another class, for this I will use jsp file for view section and Servlet class files for
controller section these files will access all input data from the viewed forms and
validate them and then will transfer them to Java Bean class (here Java Bean class
will come under model) these classes will interact with the database; they will
save data into database and fetch data from the database and then send back to
controller classes these are Java Servlet classes and then these classes will output
data to JSP forms to display to user.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Here is List of classes according to MVC pattern:
A. View package
1. index.html: this is home page with login fields and the registration link.
2. Login.jsp
3. Registeration.jsp
4. adminPanel.jsp
5. addNewOwnerDetails.jsp
6. viewAllItemDetailsWithImages.jsp
7. userPanel.jsp
8. viewAllBidItemList.jsp
9. viewNotifications.jsp
B. Controller package
All controller class will be servlet class these classes will contact with the java bean
classes.
1. validateAndSaveUserRegistrationDetails.java
2. validateLoginUserDetails.java
3. validateAndSaveNewOwnerDetails.java
4. getAllItemDetails.java
5. getAnBidItemsForAUser.java
6. getUserNotificaition.java
C. Model package
Here DBTransaction.java class will deal with the database only this class will fetch data
from the database send back this data to concerned Servlet class and this class will also
get details from the servlet class and save these details to database.
1. Connect.java: This is the class which creates connection with the database.
2. DBTransaction.java: This class fetches data or save data from or into the database.
A. View package
1. index.html: this is home page with login fields and the registration link.
2. Login.jsp
3. Registeration.jsp
4. adminPanel.jsp
5. addNewOwnerDetails.jsp
6. viewAllItemDetailsWithImages.jsp
7. userPanel.jsp
8. viewAllBidItemList.jsp
9. viewNotifications.jsp
B. Controller package
All controller class will be servlet class these classes will contact with the java bean
classes.
1. validateAndSaveUserRegistrationDetails.java
2. validateLoginUserDetails.java
3. validateAndSaveNewOwnerDetails.java
4. getAllItemDetails.java
5. getAnBidItemsForAUser.java
6. getUserNotificaition.java
C. Model package
Here DBTransaction.java class will deal with the database only this class will fetch data
from the database send back this data to concerned Servlet class and this class will also
get details from the servlet class and save these details to database.
1. Connect.java: This is the class which creates connection with the database.
2. DBTransaction.java: This class fetches data or save data from or into the database.
Suggested use of design patterns
I. Jsp/Servlet Pattern with HTML: In this we provide a solution that has a
granularity between those extreme approaches by dividing the application in
different states. We try to transfer a state transition diagram for example,
modeled with RationalRose into HTML pages, servlets and JavaServer Pages.
Applicability:
This pattern can be used in all serlet.JSP applications.We recommend this pattern
especially in complex Web applications where may Web pages and page transitions have
to be developed.
Structure:
The structure of the Servlet/JSP pattern is shown in the following diagram
Participants:
The participants in this structure of all classes are as:
Servlet: A given request either gathers data required displaying for a given state or it
invokes the action causing a transition out of the state. This responsibility fulfill by the
“controller” in a Model-View-Controller (MVC) based application.
I. Jsp/Servlet Pattern with HTML: In this we provide a solution that has a
granularity between those extreme approaches by dividing the application in
different states. We try to transfer a state transition diagram for example,
modeled with RationalRose into HTML pages, servlets and JavaServer Pages.
Applicability:
This pattern can be used in all serlet.JSP applications.We recommend this pattern
especially in complex Web applications where may Web pages and page transitions have
to be developed.
Structure:
The structure of the Servlet/JSP pattern is shown in the following diagram
Participants:
The participants in this structure of all classes are as:
Servlet: A given request either gathers data required displaying for a given state or it
invokes the action causing a transition out of the state. This responsibility fulfill by the
“controller” in a Model-View-Controller (MVC) based application.
JavaServer Pages: These pages handles the generation of HTML code for a given
request result.
Task wrapper: Encapsulates access to the enterprise business process( back-end data
and function). This function makes the Task Wrapper the “model” in a MVC application.
HTML page: In case of static content and state transitions, we do not require complex
technologies. An HTML page could handles the “static” states.
EJB design patterns
This factor is also known as Home Factory or Home Caching.
Structure:
The structure of the home factory pattern is showing by flowing diagram:
Participants:
request result.
Task wrapper: Encapsulates access to the enterprise business process( back-end data
and function). This function makes the Task Wrapper the “model” in a MVC application.
HTML page: In case of static content and state transitions, we do not require complex
technologies. An HTML page could handles the “static” states.
EJB design patterns
This factor is also known as Home Factory or Home Caching.
Structure:
The structure of the home factory pattern is showing by flowing diagram:
Participants:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
The participants in the home factory pattern are as:
HomeFactory
-Declares and implements an interface for:
The operation that returns the factory singleton
The operation that returns the EJB homes
EJB Client
-Uses interface declared by HomeFactory
Actual Process:
There are no much collaboration because the HomeFactory is the only class:
A single instance of Homefactory is created at run-time. This HomeFactory creates EJB
homes as defined in an externalized manner, example: by means of resource bundles or
XML files.
HomeFactory uses the metadata stored in this externalized manner for instantiating and
returning the appropriate EJB home class.
HomeFactory
-Declares and implements an interface for:
The operation that returns the factory singleton
The operation that returns the EJB homes
EJB Client
-Uses interface declared by HomeFactory
Actual Process:
There are no much collaboration because the HomeFactory is the only class:
A single instance of Homefactory is created at run-time. This HomeFactory creates EJB
homes as defined in an externalized manner, example: by means of resource bundles or
XML files.
HomeFactory uses the metadata stored in this externalized manner for instantiating and
returning the appropriate EJB home class.
References
Kelle, Peteris. "Useful Calendar & Date Picker Scripts For Web
Developers". HKDC. N.p., 2016. Web. 8 Aug. 2016.
Server, W.A., 2000. Design and Implement Servlets, JSPs, and EJBs.
Kharkar, Prasad. "MVC Architecture With Servlets And Jsp -
Thejavageek". theJavaGeek. N.p., 2013. Web. 12 Oct. 2016.
Java, Examples. "First Project Of Servlets And JSP Using MVC |
Examples Of Java".Examplesofjava.com. N.p., 2016. Web. 12 Oct.
2016.
Java Design Patterns - Example Tutorial - Journaldev". JournalDev.
N.p., 2013. Web. 12 Oct. 2016.
Java Design Patterns - Example Tutorial - Journaldev". JournalDev.
N.p., 2013. Web. 12 Oct. 2016.
How To List Records In A Database Table Using JSP And
JSTL". Codejava.net. N.p., 2016. Web. 12 Oct. 2016.
How To List Records In A Database Table Using JSP And
JSTL". Codejava.net. N.p., 2016. Web. 12 Oct. 2016.
How To Retrieve Data From Database And Display It In A Jsp Text
Fields Using Jdbc Connection - Codeproject". Codeproject.com. N.p.,
2016. Web. 12 Oct. 2016.
"Design Patterns | Object Oriented Design". Oodesign.com. N.p., 2016.
Web. 12 Oct. 2016.
Kelle, Peteris. "Useful Calendar & Date Picker Scripts For Web
Developers". HKDC. N.p., 2016. Web. 8 Aug. 2016.
Server, W.A., 2000. Design and Implement Servlets, JSPs, and EJBs.
Kharkar, Prasad. "MVC Architecture With Servlets And Jsp -
Thejavageek". theJavaGeek. N.p., 2013. Web. 12 Oct. 2016.
Java, Examples. "First Project Of Servlets And JSP Using MVC |
Examples Of Java".Examplesofjava.com. N.p., 2016. Web. 12 Oct.
2016.
Java Design Patterns - Example Tutorial - Journaldev". JournalDev.
N.p., 2013. Web. 12 Oct. 2016.
Java Design Patterns - Example Tutorial - Journaldev". JournalDev.
N.p., 2013. Web. 12 Oct. 2016.
How To List Records In A Database Table Using JSP And
JSTL". Codejava.net. N.p., 2016. Web. 12 Oct. 2016.
How To List Records In A Database Table Using JSP And
JSTL". Codejava.net. N.p., 2016. Web. 12 Oct. 2016.
How To Retrieve Data From Database And Display It In A Jsp Text
Fields Using Jdbc Connection - Codeproject". Codeproject.com. N.p.,
2016. Web. 12 Oct. 2016.
"Design Patterns | Object Oriented Design". Oodesign.com. N.p., 2016.
Web. 12 Oct. 2016.
1 out of 18
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.