Back to: Java Struts Tutorials
Create Struts 2 Application in MyEclipse
In this article, I am going to discuss How to Create Struts 2 Application in MyEclipse. Please read our previous article where we discussed Creating First Struts 2 Application. If you follow the below steps then we can easily create a Struts2 application using Eclipse IDE:
- Create a web project
 - Add Struts2 capabilities
 - Create input page (index.jsp)
 - Create the action class (Login.java)
 - Mapping of the request with the action in (struts.xml) file and defining the view components
 - Create view components (welcome.jsp)
 - Start the server and deploy the project
 
Create A Web Project
For creating a web project, go to file menu -> new -> project -> web -> Dynamic Web Project -> write project name (e.g. – First Struts) -> finish.
Add Struts2 Capabilities
To load struts 2 capabilities, right-click on your project and then go to build path -> configure build path -> click on the libraries tab -> click on the add external jars button -> select the struts 2 jar files -> ok.

Now select the 2.1 and /* as the url pattern -> finish.
Create Input Page (index.jsp)
index.jsp
<%@ taglib uri="/struts-tags" prefix="s" %> <s:form action="Login"> <s:textfield name="id" label="Email Id"></s:textfield> <s:textfield name="first_name" label="First Name"></s:textfield> <s:textfield name="password" label="Password"></s:textfield> <s:submit value="save"></s:submit> </s:form>
Create the Action Class (Login.java)
Login.java
package com.info;
public class Login
{
    private int id;
    private String first_name;
    private String password;
    public int getId ()
    {
        return id;
    }
    public void setId (int id)
    {
        this.id = id;
    }
    public String getFirst_Name ()
    {
        return first_name;
    }
    public void setFirst_Name (String first_name)
    {
        this.first_name = first_ name;
    }
    public float getPassword ()
    {
        return password;
    }
    public void setPassword (String password)
    {
        this.password = password;
    }
    public String execute ()
    {
        return "success";
    }
}
Mapping the Request with the Action In (struts.xml) File And Define The View Components
struts.xml
?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="default" extends="struts-default"> <action name="Login" class="com.Info.Login"> <result name="success">welcome.jsp</result> </action> </package> </struts>
Create View Components (welcome.jsp)
welcome.jsp
<%@ taglib uri="/struts-tags" prefix="s" %> Login Id:<s:property value="id"/><br/> First Name:<s:property value="first_name"/><br/> Password:<s:property value="password"/><br/>
Start Server and Deploy the Project
Lastly, we need to start the server and deploy our application. To do this, right-click on your project and run it as a MyEclipse server application.
In the next article, I am going to discuss the Core Components of the Struts Application. Here, in this article, I try to explain How to Create a struts 2 application in MyEclipse and I hope you enjoy this How to Create a struts 2 application in MyEclipse article.

