Librerias usadas
commons-fileupload-1.2.1.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
Paginas y XML
index.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<br/>
<s:a href="miAccion.action">Enviar...</s:a>
</body>
</html>
</pre>
resultado.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Primer programita en Struts2. <br/>
Se escribe un mensaje desde la consola del servidor (verificar)<br/><br/>
Suerte.<br/><br/>
<a href="javascript:history.back()">Regresar</a>
</body>
</html>
MiAccion.java
package org.dracof.struts2.actions;
public class MiAccion {
public String execute() throws Exception {
System.out.println("Pasando por el execute de MiAccion!");
return "success";
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="miAccion" class="org.dracof.struts2.actions.MiAccion">
<result name="success">resultado.jsp</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Basico</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Estructura del proyecto
index.jsp
consola de tomcat
resultado.jsp
Descargar war
basico.war
Descargr proyecto
ProyectoBasico.zip
Suerte.
No hay comentarios:
Publicar un comentario