Display (on JSP) an Object (From the Model) with Struts Tags

Struts provide tags to display model’s objects on JSP page. In this section we will cover it. Action is end point for Struts based application .Action interacts with model after completions of calculations and manipulations Action class will returns a key. On the behalf of this key some control flow operations.


There are following steps to display an object on view:

>>Reconfigure struts-config.xml

Add an attribute (i.e. attribute="user") in  tag that is used to map the ActionForm for into scope (request/session)

Here the attribute maps the Action-Form into a scope (The scope is by default session) under "user". Now ActionForm is set in session scope.So we can display the properties of ActionForm on JSP View .



>> On JSP View:

Import the bean tag library into the JSP as follows:
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>

Use the  tag  to output properties of the ActionForm.
SourceCode:


<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<html>
<head>
<title> World</title>
</head>
<body bgcolor="green">
<h1>You are successfully Login</h1>
<h1>welcome User,
<bean:write name="LoginForm" property="username"/>   
</h1>
</body>
</html>

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More