Creating Views
Posted on: March 3, 2011 at 12:00 AM
Creating Views

Creating Views

Struts provides their own JSP tag library for creating view. For using those library you need to import them on your page as

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

This tag library contains all the basic html tag to create a page. Consider the simple page written below
<%@ taglib prefix="s" uri="/struts-tags" %>

<s:form action="loginSuccess">
<s:textfield name="userId" label="Login ID"></s:textfield>
<s:password name="password" label="Password"></s:password>
<s:submit value="Login"></s:submit>

The action is the action in the form tag is the struts action. The form sends the data to the desired action written in the form. That action receives the form data by model and handle them appropriately. For creating a view you should create a model for that view. The action gets the form data through model.

You can create a model for the above view as

public class LoginModel implements Serializable {
	private String userId;
	private String password;

	public String getUserId() {
		return userId;

	public void setUserId(String userId) {
		this.userId = userId;

	public String getPassword() {
		return password;

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

Note- The Name of the text field in the JSP should be same as the field specified in model class.

Related Tags for Creating Views:




Advertisement null