REGISTER FREE to Receive Instant Job

Sunday, 9 November 2014

struts 2 first web application with eclipse

Example of struts 2 first web application with eclipse....

Add Struts 2 Jar file(commons-logging-1.0.4,freemarker-2.3.8,ognl-2.6.11,struts2-core-2.0.11 and xwork-2.0.4)

Step 1: Create New Dynamic Web Project

Step 2: Filter Mapping Code for Communication between web.xml to struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<!-- Filter Mapping Code for Communication between web.xml to struts.xml -->




Step 3: Create struts.xml 


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


<!-- Default struts package name-->

<package name="default" extends="struts-default">

<!-- Define action class-->
<action name="login" class="mypack.LoginAction"> <!-- Now create Action Class -->
<!-- Define result page after success  to show welcome.jsp page or if any error than show index.jsp page-->

<result name="success">/welcome.jsp</result>
<result name="input">/index.jsp</result>

Step 4: create two JSP pages welcome.jsp and index.jsp


<%@ taglib uri="/struts-tags" prefix="s"%>
 <!-- show error because library file not aviable, now add library jar file -->


<b> Welcome, <s:property value="name" /> </b>




<%@ taglib uri="/struts-tags" prefix="s" %>

<!-- Create Login form  -->

<s:form action="login">
<!-- Define action to mapp with struts.xml -->
<s:textfield name="name" label="Name" />
<s:password name="password" label="Password" />
<s:submit value="login" />



Step 5: create Java action file

package mypack;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport { // Show error because required jar file
/** * */
private static final long serialVersionUID = 1L;
/*Define variable*/
private String name, password;

public String getName() {
return name;

public void setName(String name) { = name;

public String getPassword() {
return password;

public void setPassword(String password) {
this.password = password;

public void validate() {
this.addFieldError("name", "Name is required.");
this.addFieldError("password", "Password is required.");
else if(password.length()<4)
this.addFieldError("password", "Password should be of atleast 4 characters.");


Step 6: Right Click on Project and Run Program


  1. I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs.
    Java Training in Chennai

  2. Thank you for sharing this blog. This is awesome blog for beginners. This will help to improve my JAVA knowledge.
    Struts Training in Chennai | Struts Training | Struts Training center in Chennai | Struts course in Chennai


Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.