Struts 2 Property Tag Example
Our Artist data class contains the following code.
package vaannila;
public class Artist {
private String name;
private String bio;
Artist(String name, String bio)
{
this.name = name;
this.bio = bio;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBio() {
return bio;
}
public void setBio(String bio) {
this.bio = bio;
}
}
Let's see how we can access the action class attributes using the property tag in the jsp page. The albumDetails.jsp page contains the following code.
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<s:head />
<style type="text/css">
@import url(style.css);
</style>
<title>Album Details</title>
</head>
<body>
<div class="content">
<b>Album Title :</b>
<s:property value="title" /> <br>
<b>Artist Name :</b>
<s:property value="artist.name" />
<br>
<b>Artist Bio :</b>
<s:property value="artist.bio" />
<br>
</div>
</body>
</html>
|