HOME | J2ME | Struts | AJAX | SOAP | SOA MEDIA STREAMING AXIS |
Struts for Begginers
Introduction
MVC Design Pattern
Installation
Action Servlets
Hello World
Forms & ActionForms
Messages Resources
Data Bases
Exceptions
Acess ActionForms from JSP
Logic Tag

 

 

Struts for Beginners: Accessing Action Forms from JSP Pages

Back | Tutorial Home | Next

Action Forms can be accessed from the JSP’s using “tags-bean” tag library. The below section describes the procedure to display values of the bean “LoginForm.java” in the JSP page.

Add attribute tag to the action mapping. The parameter attribute sets the LoginForm(aliased as userLoginForm in the bean defination) object to be in session scope and can be accessed from JSP pages.
<action path="/loginAction"
type="com.salsa.UserLoginAction"
name="userLoginForm"
attribute="loginBean"
input="/loginForm.jsp"
cancellable="true">

The value of the attribute parameter i.e. loginBean will now become the alias for LoginForm bean and can be accessed from any JSP page using <bean: write> tag.

<bean:write name="loginBean" property="userName" />

Make sure the required tag lib is imported.

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

Complete code of loginStatus.jsp

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<html>
<head>
<title>
Login Status
</title>
</head>
<body>
<bean:message key="login.status" />
<br>You are logged in as <b><bean:write name="loginBean" property="userName" /></b>
</body>
</html>

Back | Tutorial Home | Next

site comments powered by Disqus
Download our free toolbar

toolbar powered by Conduit

| Copyright © 2009. All rights reserved | Terms and Conditions | About | Contact | Feed Back |