Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simple struts example but it doesn't work

843836Jun 29 2005 — edited Jun 30 2005
Hello everybody,

I'm new in struts technology and I wanted try a simple struts example, but it didn't work. Here are listings of code:

*** struts-config .xml (is located in WEB-INF/) :

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<action-mappings>
<action path="/register"
type="app.RegisterAction"
name="registerForm">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
</action-mappings>
</struts-config>

*** RegisterAction.java (located in WEB-INF/classes/app):

package app;

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

public class RegisterAction extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) {
// b Cast the form to the RegisterForm
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
// c Apply business logic
if (password1.equals(password2)) {
return mapping.findForward("success");
}
// E Return ActionForward for failure
return mapping.findForward("failure");
}
}

*** RegisterForm.java (located in WEB-INF/classes/app):

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;};
}

*** faulire.html ( located webapps/NAME_APPLICATION/ )
<HTML>
<HEAD>
<TITLE>FAILURE</TITLE>
</HEAD>
<BODY>
Registration failed!
<P>try again?</P>
</BODY>
</HTML>

*** success.html ( located webapps/NAME_APPLICATION/ )
<HTML>
<HEAD>
<TITLE>SUCCESS</TITLE>
</HEAD>
<BODY>
Registration succeeded!
<P>try another?</P>
</BODY>
</HTML>

*** register.jsp ( located webapps/NAME_APPLICATION/ )
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:form action="register.do">
UserName:<html:text property="username"/><br>
enter password:<html:password property="password1"/><br>
re-enter password:<html:password property="password2"/><br>
<html:submit value="Register"/>
</html:form>

*** web.xml (located in WEB-INF/)
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>


<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

</web-app>

After start of NAME_APPLICATION it show register form (register.jsp) but when I fill out all information and submit those information it show empty window in internet browser and in url box is something like this:

http://localhost:8084/StrutsTest/register.do;jsessionid=2304C0A9820E7FCC23106C16564D51A8

where is a problem? Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 28 2005
Added on Jun 29 2005
9 comments
349 views