Struts Examples Using Eclipse: Step: 1
Struts Examples Using Eclipse: Step: 1
Step : 1
The following picture shows the directory structure of the Struts application.
Right click the Jave Resources:src folder and right click select NewSource Folder.
LoginAction.java
Mmcc Computer Centre, 38 Burkit Road, T.Nagar, Chennai-17
24323605, 9444037410 47691793.doc Page 6 of 16
package mmcc.struts2;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport
{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute()
{
if (this.username.equals("mmcc")
&& this.password.equals("mmcc123")) {
return "success";
} else {
addActionError(getText("error.login"));
return "error";
}
}
}
<body>
<h2>Struts 2 - Login Application</h2>
<s:actionerror />
<s:form action="login.action" method="post">
<s:textfield name="username" key="label.username" size="20" />
<s:password name="password" key="label.password" size="20" />
<s:submit method="execute" key="label.login" align="center" />
</s:form>
</body>
</html>
Welcome.jsp
Web.xml
Struts.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />