This page is for beginners to learn struts in easy way.

Why struts is needed?

In old coding ways we are using all code in single JSP so it is difficult to solve the error if occurs.

But in struts we are using a new framework called MVC (Model View Controller).

What is MVC?

Model : Represents Data Objects , Its what the user Manipulates and Presents to the User,ex bean logic.

View : What user going to see ie Representation of model , It is an Object of current state of Data.

Controller : Controller component is the one responsible for manipulating the model or Data Object for example servlet codes.

Advantages of MVC

1. Reliability : Split the work of a programmer and designer so it is easy to create dynamic reliable pages easy to modify later.

2. Re-Usablity : Reusing the code for example some database connection codings are reused.

3. Reduced Development Costs:Since work is splitted for ex:the programmer finish his work in two days, we give two day salary only he donot need to stay for another day for designer to finish his work.

4. Rapid Development :Quickly develop because of MVC

5. Reduced Mantainance : The MVC helps to easily maintain the projects.

Lets starts programming Just download the project and starts working in struts.

Download Source First Struts project

Note:When using tomcat for running struts certain things you must kept in mind there are as follows.

1. you need to restart tomcat server every time you change your Java code and compile and make a class file newly.
2. you need to restart tomcat server every time you change your web.xml file
3. you need to restart tomcat server every time you change your Struts-config.xml file
4. you need to restart tomcat server every time you change your ApplicationResources.properties file
5. you Don’t need to restart tomcat server every time you change your Image File JPG or GIF
6. you Don’t need to restart tomcat server every time you change your HTML file
7. you Don’t need to restart tomcat server every time you change your JSP file

TO RUN SERVLET IN TOMCAT 5.5
FIRST CREATE THE FOLDER STRUCTURE
LIKE BELOW
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\

UNDER WEBAPPS FOLDER
\
PROJECT FOLDER NAME
\
index.jsp
index.html
web_inf
\
classes
web.xml
in servlet url pattern give as /servletname/*
In html form action=”servletname” method=”get or post” if get then servet class will have get method doGet else doPost

To compile the servlet
set the java path
set the classpath
in cmd prompt
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\s2s\WEB-INF\classes>set classpath=C:/Program Files/Apache Software Foundation/Tomcat 5.5/common/lib/servlet-api.jar;

In command prompt complie it.

javac servletname.java

When no error shown you are almost ready to run your first servlet.

go to internet explorer http://localhost:8080/ (default)
otherwise give the appropriate port where you give at the time of installation.
1.click manager give user and password if u donot know go to tomcat install.directory/
conf/tomcat-users.xml u find there
2.click the project of yours and enjoy running servlet