This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread for details.
The moose likes Struts and the fly likes Newbie Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Newbie Problems" Watch "Newbie Problems" New topic

Newbie Problems

John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 118
I'm trying to learn struts by using the huested book.
His 1st example, a simple login type application has
about 3 html/jsp pages, and about 4 java classes
(a form, action, helper class and exception). I've
compiled & deployed everything as the book describes,
however, when I enter the information I've entered,
I get this white screen of death. The url has what I
believe the session id is, but I don't get the success
or failure page to show, as I'd expect.

I'm using netbeans5.5 as my IDE. In creating the app,
I selected the struts framework, and loaded the TLD's.
Can anybody offer any suggestions on what I am missing?


Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Show us your code, including JSPs, Action classes and the struts-config.xml file.

Consultant, Sima Solutions
John Gregory
Ranch Hand

Joined: Oct 05, 2006
Posts: 118

Here are the pages you mentioned:


<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="form" %>

<form:form action="">
UserName:<form:text property="username"/><br>
enter password:<form assword property="password1"/><br>
re-enter password:<form assword property="password2"/><br>
<form:submit value="Register"/>

//success && failure.html -- only difference is in name and message.

Registration succeeded!
<P><A href="register.jsp">try another?</A></P>
package app;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class RegisterAction extends Action {

public ActionForward perform (ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) {

// (1) Cast the form to the RegisterForm
RegisterForm rf = (RegisterForm) form;

String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();

// (2) Apply business logic
if (password1.equals(password2)) {

try {
// (3) Return ActionForward for success
return mapping.findForward("success");
} catch (UserDirectoryException e) {
return mapping.findForward("failure");

// (4) Return ActionForward for failure
return mapping.findForward("failure");


package app;
import org.apache.struts.action.*;

public class RegisterForm extends ActionForm {
protected String username;
protected String password1;
protected String password2;

public String getUsername () {return this.username;};
public String getPassword1() {return this.password1;};
public String getPassword2() {return this.password2;};

public void setUsername (String username) {this.username = username;};
public void setPassword1(String password) {this.password1 = password;};
public void setPassword2(String password) {this.password2 = password;};

package app;

import java.util.Enumeration;
import java.util.Properties;

public class UserDirectory {

private static final String UserDirectoryFile = "resources/";
private static final String UserDirectoryHeader = "${user}=${password}";
private static UserDirectory userDirectory = null;
private static Properties p;

private UserDirectory() throws UserDirectoryException { i = null;
p = null;
i = this.getClass().getClassLoader().

if (null==i) {
throw new UserDirectoryException();
else {
try {
p = new Properties();
catch ( e) {
p = null;
throw new UserDirectoryException();
finally {
i = null;
} // end else

public static UserDirectory getInstance() throws UserDirectoryException {

if (null==userDirectory) {
userDirectory = new UserDirectory();
return userDirectory;


public String fixId(String userId) {
return userId.toUpperCase();

public boolean isValidPassword(String userId, String password) {
if (null==password) return false;

String _userId = fixId(userId);

if (!isUserExist(_userId)) return false;
return (password.equals(getPassword(_userId)));

public boolean isUserExist(String userId) {
if (null==userId) return false;
return !(null==p.getProperty(userId));

public String getPassword(String userId) {
return p.getProperty(userId);

public Enumeration getUserIds() {
return p.propertyNames();

public void setUser(String userId, String password) throws UserDirectoryException {

if ((null==userId) || (null==password)) {
throw new UserDirectoryException();

try {
p.put(fixId(userId), password);
String o = this.getClass().getClassLoader().getResource(UserDirectoryFile).getFile(); FileOutputStream(o), UserDirectoryHeader);
catch (IOException e) {
throw new UserDirectoryException();
} // end UserDirectory


<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"


<form-bean name="registerForm" type="app.RegisterForm"/>

<action path="/register"
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The problem appears to be with the name of the method in your RegisterAction. It should be execute instead of perform. This is something that has changed since earlier versions of Struts. Another thing to watch out for is that in your JSP, the html:form tag should no longer have a name or type attribute. Just specify action and that will be sufficient.

Also, for future reference, when posting code, please highlight the code and press the code button. This will preserve the indents in your code and make it much easier to read.
[ September 01, 2007: Message edited by: Merrill Higginson ]
I agree. Here's the link:
subject: Newbie Problems