index.jsp
Código:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:forward page="Form.do"/>
RegistroForm.java
Código:
package javabeans;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
public class RegistroForm extends ActionForm {
private String nombre;
private String apellidos;
private String usuario;
private String password;
private String email;
//metodos de acceso
public String getNombre() {
return nombre;
}//Fin del getnombre
public void setNombre(String nombre) {
this.nombre = nombre;
}//Fin del setNombre
public String getApellidos() {
return apellidos;
}//Fin del getAmeppidos
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}//Fin del setApellidos
public String getUsuario() {
return usuario;
}//Fin del getUsuario
public void setUsuario(String usuario) {
this.usuario = usuario;
}//Fin del setUsuario
public String getPassword() {
return password;
}//Fin del getPassword
public void setPassword(String password) {
this.password = password;
}//Fin del setPassword
public String getEmail() {
return email;
}//Fin del getEmail
public void setEmail(String email) {
this.email = email;
}//Fin setEmail
}//Fin del la clase
Formulario.jsp
Código:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html:html>
<body>
<center>
<h1>Registro de Usuario</h1>
<html:form action="/registrar" method="POST">
<table>
<tr>
<td>Nombre:</td>
<td><html:text property="nombre"/></td>
</tr
<tr>
<td>Apellidos:</td>
<td><html:text property="apellidos"/></td>
</tr>
<tr>
<td>Usuario:</td>
<td><html:text property="usuario"/></td>
</tr>
<tr>
<td>Password:</td>
<td><html:password property="password"/></td>
</tr>
<tr>
<td>Email:</td>
<td><html:text property="email"/></td>
</tr>
</table>
<html:submit property="submit" value="Registrar"/>
<html:reset value="Limpiar"/>
</html:form>
</center>
</body>
</html:html>
struts-config.xml
Código:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="RegistroForm" type="javabeans.RegistroForm"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
<forward name="form" path="/Form.do"/>
</global-forwards>
<action-mappings>
<action path="/Form" forward="/Formulario.jsp"/>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="com/myapp/struts/ApplicationResource"/>
<!-- ========================= Tiles plugin ===============================-->
<!--
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
module).
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation
Paths found in Tiles definitions are relative to the main context.
-->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>