struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Almeida, Veeda" <Veeda.Alme...@i21.com>
Subject Struts - JSP does not store the user entered values when i click back
Date Thu, 05 Dec 2002 20:06:03 GMT

Good Morning,

When I load the jsp, go to next page and click on browser back button. User
entered values are not stored.

This happens everytime I open a new browser and launch the jsp page, happens
only for the first submit, does not happen otherwise.

Any ideas? Thanks in advance.

Below is the jsp and the action class :

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html
    locale="true">
<head>
<title><bean:message key="login.title"/></title>
<html:base/>
</head>
<body bgcolor="white">

<html:errors/>



<table border="1" size="100%">
    <tbody>
        <tr>
            <bean:message key="login.title"/>
        </tr>
        <html:form action="/jsp/login" focus="username">
        <tr>
            <td><bean:message key="login.username"/></td>
            <td><html:text property="username" size="16"
maxlength="16"/></td>
        </tr>
        <tr>
            <td><bean:message key="login.password"/></td>
            <td><html:password property="password" size="16" maxlength="16"
redisplay="false"/></td>
        </tr>
        <tr>
            <td align="right"><html:submit property="submit"
value="Submit"/></td>
            <td align="left"><html:reset/></td>
        </tr>
        </html:form>
    </tbody>
</table>
</body>
</html>

--------------------------------------------
package com.mypackage;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import java.io.*;

public class loginAction extends Action {

	public ActionForward perform(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response)
		throws IOException, ServletException {

		// validate user input
		ActionErrors errors = new ActionErrors();

		String username = ((loginForm) form).getUsername();
		String password = ((loginForm) form).getPassword();

		User user = new User();
		user.setFullName("username");
		user.setPassword("password");

		if (!user.getFullName().equals(username)
			|| !user.getPassword().equals(password))
			errors.add(
				ActionErrors.GLOBAL_ERROR,
				new
ActionError("username.password.mismatch"));

		// report any error back to origional form
		if (!errors.empty()) {
			saveErrors(request, errors);
			return (new ActionForward(mapping.getInput()));
		}

		// save logged-in user in session
		HttpSession session = request.getSession();
		session.setAttribute(Constants.USER_KEY, user);

		// remove the obselete form bean
		if (mapping.getAttribute() != null) {
			if ("request".equals(mapping.getScope()))
	
request.removeAttribute(mapping.getAttribute());
			else
	
session.removeAttribute(mapping.getAttribute());
		}
		// forward control to the specified success uri
		return mapping.findForward("success");

	}
} // end loginAction class



Veeda Almeida




***********************************************************************
This e-mail and any files transmitted with it are intended 
solely for the use of the addressee.  This e-mail may 
contain confidential and/or legally privileged information.  
Any review, transmission, disclosure, copying, or any action 
taken or not taken, by other than the intended recipient, in 
reliance on the information, is prohibited.  If you received 
this e-mail in error, notify the sender and delete this e-mail 
(and any accompanying material) from your computer and
network. In addition, please be advised that 21st Century 
Insurance Group reserves the right to monitor, access and 
review all messages, data and images transmitted through 
our electronic mail system. By using our e-mail system, you 
consent to this monitoring. 
***********************************************************************


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message