Session vs. Request Scope ActionForm
Previous | Home | Next |
Scope specifies the scope of the form bean that is bound to the describes Action..
You are using request scope the values of form bean would be available for one the current request.One the response has been returned to the client the actionform and the data within it are no langer accessible.but In the session , the values of form bean would be available throughout the session.struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="loginForm" type="com.r4r.struts.LoginForm"/> </form-beans> <global-exceptions /> <global-forwards> <forward name="login" path="/login.do"/> </global-forwards> <action-mappings> <action path="/login" type="com.r4r.struts.LoginAction" name="loginForm" scope="request/session"> <forward name="success" path="/success.jsp"/> <forward name="error" path="/error.jsp"/> </action> </action-mappings> <message-resources parameter="com.r4r.struts.ApplicationResources"/> </struts-config>Scope attributes:-The scope attribute is used to define scope for request or session .<action-mappings><action path="/login" scope="request/session"> <forward name="success" path="/success.jsp"/> <forward name="error" path="/error.jsp"/> </action> </action-mappings>In this example, scope is set session so the values of form bean would be available throughout the session.<action input="/login.jsp" name="LoginForm"path="/Login" scope="session" type="com.r4r.LoginAction">
Previous | Home | Next |