InSight: RIVIER ACADEMIC JOURNAL, VOLUME 14, NUMBER 1, FALL 2018
Copyright©2018 by Saroj Maharjan. Published by Rivier University, with permission 1
ISSN 1559-9388 (online version), ISSN 1559-9396 (CD-ROM version).
Abstract
There are a number of framework technologies which can be used to develop web applications. But
since the web applications are getting more complex over time, the frameworks that can used to develop
them should also be advanced to handle the complex requirements. This project walks us thorough
Struts framework, which is one of most popular and used web application frameworks. The project was
part of the final project implemented for CS699 “Professional Seminar in Computer Science” course
which is based on the research on Struts framework and a web application which was developed based
on Struts. This article summaries the benefits of using Struts framework in web application, its
comparison with LAMP technology, drawbacks of Struts and finally, the web application which was
developed following the software development steps.
1 Introduction
Struts is a complete web framework, provides complete web form components, validator,
internalization, error handling, tiles layout, low learning curve and easy to implement it. It is an open
source software that helps developers build web applications quickly and easily. Struts combines Java
Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a
cooperative, synergistic platform suitable for development teams, independent developers, and everyone
in between.
1
And J2EE is actually a collection of technologies and APIs for the Java platform designed
to support "enterprise" applications which can generally be classed as large-scale, distributed,
transactional and highly-available applications designed to support mission-critical business
requirements.
2
MVC (Model View Controller), on the other hand, is a design pattern which separates the
representation of information from the user's interaction with it. The model contains the business logic
and interacts with the persistent storage to store, retrieve and manipulate data. The view is responsible
for displaying the results back to the user. In Struts the view layer is implemented using JSP. The
controller handles all the request from the user and selects the appropriate view to return. And the
controller's job is done by the ActionServlet.
3
1.1 How does Struts work?
Apache Struts implements the MVC/Layers pattern using ActionForwards and ActionMappings to keep
control-flow decisions out of the presentation layer. When the Client browser issues an HTTP request,
the ActionServlet receives the request. Then after struts-config.xml file contains the details regarding the
Actions, ActionForms, ActionMappings and ActionForwards. During the startup, the ActionServlet
1
n.d. Apache Struts - Welcome to the Apache Struts Project. struts.apache.org.
2
1997. DZone. Accessed October 20, 2018. http://www.dzone.com/tutorials/css/struts.
3
2000. FYIcenter. Accessed November 10, 2018. http://dev.fyicenter.com.
SOCIAL NETWORKING WEB APPLICATION USING STRUTS
FRAMEWORK
Saroj Maharjan*
Student, M.S./Computer Science Program, Rivier University
Saroj Maharjan
2
reads the struts-config.xml file and creates a database of configuration objects. Later while processing
the request, the ActionServlet decides by referring to this object.
4
LAMP suite is another the technology that I learned in my undergraduate Internet Programming
course. LAMP is an acronym for a solution stack of free, open source software, originally coined from
the first letter of Linux (operating system), Apache HTTP Server, MySQL (database software) and PHP.
1.2 Why I chose Struts?
I decided to use Struts to develop my web application, which is very different from LAMP suite because
after learning about struts, I found that it would be very beneficial working with it for my project with its
many helpful features. The Struts framework resides in the web-tier. Struts applications are hosted by a
web container and can make use of services provided by the container, such as handling requests via
HTTP and HTTPS protocols which lets developers focus on building applications that solve business
problems. In Struts properties files are used for storing all variables so that the application has no hard
coding.
Suppose a web application has a large scope and acts with several JSPs. Since large volumes of
requests and responses to/from server, the controller becomes very complicated. In that case, Struts
makes it easier. Struts has an in-built servlet (Action servlet) that takes care of these and controls the
navigational flow, reducing the overhead and making the job simpler, which was very beneficial for the
project.
Struts follows a well-defined order, and every programmer must follow that order. There is a
particular servlet as a controller in which every request goes through, in the same way the Struts
framework provides a way in which they implicitly define all that controller functionality, we don't have
to care about that. Struts combines with JSP, Servlets, custom tag, message resource, and action classes,
so the end result is a synergistic platform, which makes developing web applications easier and reduces
the number of developers. It is also easy to troubleshoot whenever an error occurs, and with its tag
library, we can easily create JSPs.
5
In a simple web application, we can use PHP and implement their SQL queries and the business
logics directly in the HTML document. The source code looks like following example:
<html>
<head>
<title>Sample Title</title>
</head><br>
<body><br><someScript><br>dbConnection = openDBConnection(someDB)<br>resultSet =
dbConnection.executeQuery('select bookName from books')<br>loop over resultSet{<br>
print (resultSet.field('bookName') + '<br>')<br>}<br></someScript><br>
</body>
</html>
6
It is convenient in small projects or projects with less coding. But, in real world, suppose we have
more than 100 code or dialogs, many database queries in this dialog and we want to define a field status,
4
Ibid.
5
1997. DZone. Accessed October 20, 2018. http://www.dzone.com/tutorials/css/struts.
6
n.d. Apache Struts - Welcome to the Apache Struts Project. struts.apache.org.
3
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
setting if a field is deleted or not. To alter functions and database queries easily, we should separate
these from the dialogs. Struts separates the dialogs and business logic (functionality). It helps with
changes on the functionality, without working in the dialogs and easier to maintain an application with
better overview, which was very helpful.
Another helpful feature for the project was the Struts Mapping. Struts values/mapping is
represented in XML or property files. The loose coupling means that many changes can be made
without modifying or recompiling Java code and that wholesale changes can be made by editing a single
file.
7
This approach also lets Java and Web developers like us to focus on their specific tasks
(implementing business logic, presenting certain values to clients, etc.) without needing to know about
the overall system layout, which would have been very difficult if I had done with the LAMP suite.
Struts has many other helpful capabilities. If I did not want to translate a dialog, I can put the dialog
texts directly into the JSP File. For example, we have a sample code in JSP as:
<html:form action="someAction"><br>
Please give your name and the book title <br>
<br>Name:<br> <html:text property="name"/> <br>
<br> Title:<br> <html:text property="title"/> <br>
<br> <html:submit/><br>
</html:form>
8
Struts support resources files. In this file we can define a key for a text like:
bookDialog.formIntro=Please give your name and the title of the book.
bookDialog.inputName=Name:
bookDialog.bookTitle=Title:(Apache Software Foundation)
This key can be used to display the text in the JSP file, which is very helpful.
<html:form action=“someAction”>
<bean:message key=“bookDialog.formIntro”/> <br>
<bean:message key=“bookDialog.inputName”/>
<html:text property=“name”/> <br>
<bean:message key=“bookDialog.bookTitle”/>
<html:text property=“title”/> <br>
<html:submit/>
</html:form>
9
Struts also saves error messages in the business logic and can display this in the dialogs. We can
show all errors or bind an error to a field and show the error beside of it. The error messages are added
to the resource files, so the errors can be internationalized too. Struts supports a complete solution to
validate form fields, such as a valid date, an email, a number, or anything else, so it is very much helpful
in web development. I only had to define which form field will be checked and which error message will
7
1997. DZone. Accessed October 20, 2018. http://www.dzone.com/tutorials/css/struts.
8
n.d. Apache Struts - Welcome to the Apache Struts Project. struts.apache.org.
9
Ibid.
Saroj Maharjan
4
be displayed. Struts also uses the Front Controller and Command patterns which can handle
sophisticated controller logic. In addition to the core controller function, it has many add-on benefits
such as layouts with Tiles, declarative exception handling, and internationalization.
10
I found LAMP suite technology and Struts differs in many ways. In my previous Internet
Programming course, we used LAMP to create HTML or PHP pages managed by the SQL database.
The dialogs and their functionalities were connected. So, if we needed to change or delete certain
dialogs, we had to change all other functionalities related to it. Also, it doesn’t have features like error
handling, validation, resource files, etc., which make developers spend a lot of time working on those
things. Thus, I found working with Struts and J2EE was much easier than LAMP suite, in a way that it
provides developers with very helpful features, as I mentioned above, that help developers for an
efficient and quick web application development.
2. A Social Networking Web Application - ConnectRivier
Here’s an overview of the application. Users must register before using ‘ConnectRivier’ after which
they can create their profile. The profile can be created with lists of personal interests, contact
information, and other information. Users can share their ideas, note or pictures on their profile, which
are also visible to other users. ‘ConnectRivier’ has search functionality, which will autocomplete by
displaying a list of similar users as the user types in. The user will be able to search for other users,
check their profile and add them to their friend list. A user can also change their profile details if he/she
wants to. If a user doesn’t want to use ‘ConnectRivier’ anymore, he/she can completely delete their
account. All the user information will be securely stored in the database.
3. Functional Specification
A functional specification is documentation that describes the requested behavior of an engineering
system. The documentation typically describes what is needed by the system user as well as the
requested properties of inputs and outputs.
11
It picks up the results of the requirement analysis stage.
Here is the functional specification of this project:
3.1 The System Functionality
The application shall provide the following functionality for all users:
User should be able to sign up using the user details
User should be able to sign in using the correct user credentials and sign out once done
User should be redirected to the login page in case of incorrect username or password
User should have the option if the password is forgotten
User should be able to view/edit his profile information
User should be able to search for friends and add him/her as a friend
User should have the option to delete his account
User should be able to post text, photo or video
User should have the option to view post from all his friends
10
2000. FYIcenter. Accessed November 10, 2018. http://dev.fyicenter.com.
11
n.d. LucidChart. Accessed November 10, 2018. https://www.lucidchart.com.
5
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
3.2 Use Case Diagram
Use case diagrams allow the analyst to model the interaction of an information system and its
environment. The environment of an information system includes both the end user and an external
system that interacts with the information system.
12
Figure 1: Use Case Diagram for ConnectRivier
The use case diagram for ConnectRivier has various use cases as shown in Fig. 1. Here, the actors
are users who use the application, whereas admin are able to manage and delete the user accounts. Some
of the use cases are user registration, email verification, login, log out, manage the account, delete the
account, write a post, go to dashboard, search user, add and delete a friend.
3.3 Class Diagram
Class diagrams are one of the most useful types of diagrams in UML as they clearly map out the
structure of a particular system by modeling its classes, attributes, operations, and relationships between
objects.
13
12
Ibid.
13
n.d. LucidChart. Accessed November 10, 2018. https://www.lucidchart.com.
Saroj Maharjan
6
Figure 2a: Class Diagram for classes in Dao package
The class diagram in Fig. 2a shows the structure and relationship between classes within the Dao
package. ‘Dao’ package contains the classes which are used to connect, read and write to the database.
Figure 2b: Class Diagram for classes within Dao and Entity package
7
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
The class diagram in Fig. 2b shows the structure and relationship between classes within Dao and
Entity package. The Entity package contains the POJO (Plain Old Java Object) classes which are the
entities used in the application.
Figure 3: Class Diagram for classes within Dao and service package
The class diagram in Fig. 3 shows the structure and relationship between classes within Dao and
service package. Service package contains the classes that make service calls to the database for POJO
classes.
Saroj Maharjan
8
Figure 4: Class Diagram for classes within Dao, service and action package
The class diagram in Fig. 4 shows the structure and relationship between classes within Dao,
service and action package. Classes within action package perform actions for form and service classes.
Service package contains the classes that make service calls to the database for POJO classes.
3.4 Sequence Diagram
Sequence diagram specifically focuses on lifelines or the processes and objects that live simultaneously,
and the messages exchanged between them to perform a function before the lifeline ends.
14
14
n.d. LucidChart. Accessed November 10, 2018. https://www.lucidchart.com.
9
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
Figure 5: Sequence Diagram of Registration and Login Process
The sequence diagram in Fig. 5 shows the registration and login process in sequence. Here, the user
goes sequence of actions before logging into the application. If the user has not signed up of the
application, the user can do so with his/her details. The details will be properly saved into the database.
Further, if the user enters correct user credentials, then he will be directed to the home page. Otherwise,
an error message will be shown. If the user forgets the password, a temporary password will be provided
once the user enters the valid email id.
Saroj Maharjan
10
Figure 6: Sequence Diagram for Creating a Post
The sequence diagram in Fig. 6 shows the sequence of actions required for creating a post. The user
needs to first go to ‘new post’ page, then select for the type of post he wants to create. After the post has
been created, the user also needs to type his/her password for verification. If the correct password is
entered, the post will be published. Otherwise, an error message will be shown.
11
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
Figure 7: Sequence Diagram for Managing the Account
The sequence diagram in Fig. 7 shows the sequence of actions required for managing the account.
The user first needs to go to the settings page, where his information can be edited or he can change his
password. If the information is provided in the correct format, then those are saved into the database and
are reflected in the profile page. If the user wished to delete his account, then he can select the ‘delete
account’ option and enter his password. If the information is correct, then the account will be
permanently deleted from the databases. Otherwise, an error message will be displayed.
3.5 Activity Diagram
An activity diagram is essentially a flowchart that shows activities performed by a system.
Saroj Maharjan
12
Figure 8: Activity Diagram of ConnectRivier
The activity diagram in Fig. 8 shows various activities users can perform in the application after
successfully logging in a before logging out.
4. System Design Specifications
4.1 Architecture Diagram
Figure 9: Architecture Diagram of ConnectRivier
13
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
Figure 9 shows the architecture diagram of ConnectRivier application which is based on the Struts
framework. Since Struts is based on MVC framework, here model contains all the business logic and
interaction with the database, the view contains the JSP and HTML pages, and controller handles all the
requests form the user which is done by ActionServlet. Struts-config.xml file contains the details
regarding the Actions, ActionForms, ActionMappings and ActionForwards. During the application
startup, the ActionServlet reads the struts-config.xml file and creates a database of configuration objects.
Later while processing the request, the ActionServlet decides by referring to this object.
4.2 Deployment Diagram
Figure 10: Deployment Diagram of ConnectRivier
ConnectRivier is deployed using the tomcat web server which runs as struts application within the
application server. It uses MySQL Server for the JDBC connection (see Fig. 10).
Saroj Maharjan
14
4.3 Package Diagram
Figure 11: Package Diagram of ConnectRivier
Figure 11 shows the package diagram of ConnectRivier and the dependencies of the packages. The
following packages have been used: resources, entity, form, db.dao, db.service, action, and
searchEngine. Other packages are in-built from the struts and servlets framework.
5. Programming environment and tools
As the development environment, I used Eclipse IDE, Java/J2EE, JSP, HTML, CSS, JavaScript, and
Ajax to create web pages. And for the database, I used MySQL, which is connected using Java Database
Connectivity (JDBC) method. I used the Windows platform with Tomcat v7.0 as my server. In
summary, the following tools have been used:
IDE - Eclipse JEE 2018-09
Language - Java 8
Database - MySQL
Framework - Struts, Servlet
Cloud Server - Amazon Web Services (AWS)
Tools - LucidChart, GitHub.
6. Unit/Module Tests, Integration Tests and Functional Tests
Various test cases including unit tests, integration tests and functional tests were created and tested in
the application. The results showed that all of the test cases had passed.
7. Prototype and Demonstration
The ‘ConnectRivier’ project was presented in the class of CS699 “Professional Seminar in Computer
Science” (Instructor: Dr. Vladimir Riabov) on November 28, 2018. It included the demonstration of the
application with its features. Below (see Figs. 12-18) are screenshots of various pages from the
application.
15
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
Figure 12: Welcome page
Figure 13: User Profile page
Saroj Maharjan
16
Figure 14: Home page
Figure 15: Account Settings page
17
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
Figure 16: Creating a Post page
Figure 17: Forgot Password page
Saroj Maharjan
18
Figure 18: Searching for Friends
8. Drawbacks of Using Struts
Some of the drawbacks that I found while using Struts over Lamp are that Struts was harder to learn,
benchmark and optimize than LAMP suite. Also, to use MVC with Struts, first I had to be comfortable
with the standard JSP and servlet APIs and a large and elaborate framework that is almost equal in size
to the core system. And I also sometimes found it was difficult to debug with the various .xml files that
Struts relies on. Also, some JSP tags were slightly confusing. Whereas, on the other hand, developing
web pages using Lamp technology, took me less time to understand all the basic operations. Using
LAMP, it was easy to code with PHP and MySQL, easy to deploy the PHP app, and once we have got
MySQL running, we can simply upload our PHP files. It could be developed locally and had a cheap and
ubiquitous hosting. It was easy to code and has an easy deployment. And there was a smaller number of
errors, which could be handled easily.
9. Things I Learnt
The things that I learned from this project are that learning other resources besides the course study are
really helpful and are also applicable in real-world. Before doing something we have to set a goal or
plan and finally I got a chance to learn many new technologies such as JSP, struts and how to integrate
and also create a dynamic web application using J2EE tools. Few problems that I encountered during the
experience were, at first it took me a lot of time to learn the new design framework, so I had to manage
the time wisely, simple errors in coding caused the whole system to crash, and I had some issues while
setting up the server and connecting my local database. As the solution, I found that eclipse is really
helpful with debugging. Also, the struts is very user-friendly with building web applications.
10. Conclusions
The overall project experience was great: I learnt a lot about Struts methodology and applied it and
many other technologies successfully to develop my own ConnectRivier application. Though there were
many challenges while starting to build the application, I found Struts really helpful in creating web
applications. It was a great learning experience with bug fixing and setting up the environment in AWS.
Overall, I am glad that it turned out the way that I had anticipated I would be.
19
SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK
11. References
1. C. Lei, "Software Project Management Based on Struts Architecture," In Proceedings of the 2015
International Conference on Intelligent Transportation, Big Data & Smart City (ICITBS), Halong
Bay, Vietnam, 2015, pp. 733-736. doi:10.1109/ICITBS.2015.185
2. n.d. Apache Struts - Welcome to the Apache Struts Project. http://struts.apache.org.
3. 1997. DZone. Accessed October 20, 2018. http://www.dzone.com/tutorials/css/struts.
4. 2000. FYIcenter. Accessed November 10, 2018. http://dev.fyicenter.com.
5. n.d. Learn Servlet Tutorial - Javatpoint. Accessed October 20, 2018. www.javatpoint.com/servlet-
tutorial.
6. n.d. LucidChart. Accessed October 20, 2018. https://www.lucidchart.com.
7. Mkyong. 2010. Struts Tutorial. May 2. Accessed November 10, 2018.
www.mkyong.com/tutorials/struts-tutorials/.
___________________
*
Saroj Maharjan is an international student from Nepal and has completed the master’s degree from Rivier University in
fall 2018 with a major in Computer Science. Saroj earned his undergraduate degree from Truman State University, with a
major in Computer Science and minor in Mathematics. He has been working as a software engineer for almost four and a
half years. Currently, he is working for Persivia Inc., which is located in Marlborough, MA. Learning new skills and
implementing the acquired knowledge to develop useful tools have always been his passion. With all the knowledge and
experience Saroj gained throughout his Rivier journey and working professionally for almost half a decade drove him
towards the passion for achieving his goals.