<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rails y más cosas &#187; struts</title>
	<atom:link href="http://www.railsymas.com/category/struts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsymas.com</link>
	<description>Nuevas Tecnologías</description>
	<lastBuildDate>Sat, 28 Jan 2012 10:23:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Tutorial de struts</title>
		<link>http://www.railsymas.com/2011/05/29/tutorial-de-struts/</link>
		<comments>http://www.railsymas.com/2011/05/29/tutorial-de-struts/#comments</comments>
		<pubDate>Sun, 29 May 2011 09:43:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2255</guid>
		<description><![CDATA[El siguiente post es una recopilación de diferentes enlaces del sitio web relacionados con el framework struts Un framework que se puede considerar como el padre de los frameworks actuales modernos, creado en Originalmente fue creado por Craig R. McClanahan y donado al proyecto Jakarta de Apache Software Foundation en el año 2000. En Junio [...]]]></description>
			<content:encoded><![CDATA[<p>El siguiente post es una recopilación de diferentes enlaces del sitio web relacionados con el framework struts</p>
<p>Un framework que se puede considerar como el padre de los frameworks actuales modernos, creado en Originalmente fue creado por Craig R. McClanahan y donado al proyecto Jakarta de Apache Software Foundation en el año 2000. En Junio de 2001 se libera la primera versión, y desde entonces muchos desarrolladores han participado en la mejora continua de este frameworks</p>
<p> <span id="more-2255"></span></p>
<p>Struts se basa en el patrón de arquitectura de software Modelo-Vista-Controlador (MVC) el cual se utiliza ampliamente y es considerado de gran solidez. De acuerdo con este Framework, el procesamiento se separa en tres secciones diferenciadas llamadas el modelo, las vistas y el controlador.</p>
<p>Los frameworks actuales basados en la tecnología jee automatizan todos los aspectos de struts facilitando el desarrollo de manera considerable.</p>
<p>Ejemplos realizados con la versión 1.3.10 de struts y también 1.2.x datasource y tags struts</p>
<ul>
<li> <span style="font-size:16px;">  1<a href="http://www.railsymas.com/2009/07/24/introduccion-a-struts-con-eclipse/">Introducción a struts con eclipse </a></span></li>
<li> <span style="font-size:16px;">  2 <a href="http://www.railsymas.com/2009/08/01/formulario-login-struts-eclipse/">Creación de un formulario de login con struts</a></span></li>
<li> <span style="font-size:16px;weight:bold">  3 <a href="http://www.railsymas.com/2009/08/03/formulario-login-struts-2-parte/">Creación de un formulario de login segunda parte</a></span></li>
<li> <span style="font-size:16px;weight:bold">   4<a href="http://www.railsymas.com/2009/08/04/crear-una-ventana-de-error-404-y-500-en-struts-con-eclipse/"> Crear una ventana de error 404-500 en struts</a></span></li>
<li> <span style="font-size:16px;weight:bold">   5 <a href="http://www.railsymas.com/2009/08/19/formulario-dynaactionform-struts-eclipse/">Formulario dynaactionform struts eclipse</a></span></li>
<li> <span style="font-size:16px;weight:bold">   6 <a href="http://www.railsymas.com/2009/09/14/struts-formulario-dynavalidatorform-proyecto-web-eclipse/">Formulario dynavalidatorform proyecto web eclipse</a></span></li>
<li> <span style="font-size:16px;weight:bold">   7 <a href="http://www.railsymas.com/2009/09/18/struts-dispatchaction-eclipse/">Struts dispatchaction eclipse</a</span></li>
<li> <span style="font-size:16px;weight:bold">   8 <a href="http://www.railsymas.com/2009/09/30/ibatis-proyecto-web-eclipse/">Ibatis proyecto web eclipse</a></span></li>
<li> <span style="font-size:16px;weight:bold">   9 <a href="http://www.railsymas.com/2009/10/25/struts-tiles-proyecto-web-eclipse/">Struts tiles proyecto web eclipse</a></span></li>
<li> <span style="font-size:16px;weight:bold">   10 <a href="http://www.railsymas.com/2009/10/30/struts-tiles-eclipse-2-parte/">Struts tiles 2ª parte </a></span></li>
<li> <span style="font-size:16px;weight:bold">   11 <a href="http://www.railsymas.com/2009/11/04/tutorial-html-struts-tags/">Html struts tags </a></span></li>
<li> <span style="font-size:16px;weight:bold">   12 <a href="http://www.railsymas.com/2011/05/25/struts-bean-tags/">struts bean tags </a></span></li>
<li> <span style="font-size:16px;weight:bold">   13 <a href="http://www.railsymas.com/2009/11/20/tutorial-de-lookupdispatchaction-struts/">Tutorial de lookupdispathaction struts </a></span></li>
<li> <span style="font-size:16px;weight:bold">   14 <a href="http://www.railsymas.com/2009/12/14/datasource-struts-1-2-x-proyecto-web-eclipse/">Datasource struts 1.2.x proyecto web eclipse </a></span></li>
<li> <span style="font-size:16px;weight:bold">   15 <a href="http://www.railsymas.com/2010/01/11/datasource-struts-1-3-x-proyecto-web-eclipse/">Datasource struts 1.3.x proyecto web eclipse </a></span></li>
<li> <span style="font-size:16px;weight:bold">   16 <a href="http://www.railsymas.com/2010/02/09/mostrando-listado-de-datos/"> Mostrando listado de datos </a></span></li>
<li> <span style="font-size:16px;weight:bold">   17 <a href="http://www.railsymas.com/2010/04/27/desarrollo-web-uploadfile-struts/"> Uploadfile struts </a></span></li>
<li> <span style="font-size:16px;weight:bold">   18 <a href="http://www.railsymas.com/2010/05/05/desarrollo-web-multiples-archivos-de-configuracion-struts/">Desarrollo web múltiples archivos de configuración struts  </a></span></li>
<li> <span style="font-size:16px;weight:bold">   19 <a href="http://www.railsymas.com/2010/05/14/desarrollo-web-comodines-struts/">Desarrollo web comodines struts  </a></span></li>
<li> <span style="font-size:16px;weight:bold">   20 <a href="http://www.railsymas.com/2010/05/23/creacion-de-un-plugin-con-struts-xml-dom/">Creación de un plugin con struts xml dom  </a></span></li>
<li> <span style="font-size:16px;weight:bold">   21 <a href="http://www.railsymas.com/2010/06/16/hibernate-tools-para-eclipse/">Hibernate tools para eclipse </a></span></li>
<li> <span style="font-size:16px;weight:bold">   22 <a href="http://www.railsymas.com/2010/06/25/integracion-struts-hibernate/">Integración struts hibernate </a></span></li>
<li> <span style="font-size:16px;weight:bold">   23 <a href="http://www.railsymas.com/2010/12/17/pruebas-con-el-fichero-de-configuracion-de-hibernate/"> Pruebas con el fichero de configuración de hibernate </a></span></li>
<li> <span style="font-size:16px;weight:bold">   24 <a href="http://www.railsymas.com/2011/04/20/modificando-datos-struts-hibernate/"> Modificando datos struts hibernate </a></span></li>
<ul>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/05/29/tutorial-de-struts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Struts logic tags</title>
		<link>http://www.railsymas.com/2011/05/27/struts-logic-tags/</link>
		<comments>http://www.railsymas.com/2011/05/27/struts-logic-tags/#comments</comments>
		<pubDate>Fri, 27 May 2011 11:34:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2262</guid>
		<description><![CDATA[Resumen de las etiquetas logic para struts Dentro de una página jsp declaramos la siguiente línea de texto para la importación de la librería bean &#60;%@taglib uri=&#34;http://struts.apache.org/tags-logic&#34; prefix=&#34;logic&#34; %&#62; Tabla de etiquetas logic iterate Redirige a la url indicada redirect Recorre una colección iterando sobre los elementos Tabla para las propiedades iterate id Nombre de [...]]]></description>
			<content:encoded><![CDATA[<p> Resumen de las etiquetas logic para struts </p>
<p> <span id="more-2262"></span></p>
<p> Dentro de una página jsp declaramos la siguiente línea de texto para la importación de la librería bean</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-logic&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;logic&quot;</span> <span style="color: #339933;">%&gt;</span></pre></div></div>

<p><br/></p>
<p><strong>Tabla  de etiquetas logic </strong></p>
<table border="1" caption="listado de struts logic tags">
<tr>
<td>iterate</td>
<td> Redirige a la url indicada</td>
</tr>
<tr>
<td>redirect</td>
<td> Recorre una colección iterando sobre los elementos</td>
</tr>
</table>
<p><br/></p>
<p><strong>Tabla para las propiedades iterate </strong></p>
<table border="1" caption="listado de struts bean tags">
<tr>
<td>id</td>
<td>Nombre de la variable que se declara para acceder al elemento actual de la iteracción </td>
</tr>
<tr>
<td>collection</td>
<td> Indica una expresión que devuelve una colección para iterar</td>
</tr>
<tr>
<td>indexId</td>
<td>Indica el nombre de la variable que contendrá el indice actual de la interacción</td>
</tr>
<tr>
<td>length</td>
<td>Indica el número máximo de iteracciones, puede ser un integer o un bean con valor</td>
</tr>
<tr>
<td>offset</td>
<td>Indica el índice inicial</td>
</tr>
<tr>
<td>name</td>
<td>Indica el nombre del bean que es la colección a iterar, si no se usa property</td>
</tr>
<tr>
<td>type</td>
<td>Indica el nombre completo de la clase java  asociada a la variable id</td>
</tr>
</table>
<p><br/></p>
<p><strong>Tabla para propiedades de redirect</strong></p>
<table border="1" caption="listado de propiedades de redirect logic">
<tr>
<td>name</td>
<td>Nombre del bean que contiene un Map para los</td>
</tr>
<tr>
<td>page</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td></td>
</tr>
<tr>
<td>paramScope</td>
<td>Inidia el ámbito del bean que devuelve el valor del parámetro.</td>
</tr>
<tr>
<td>transaction</td>
<td>si es true agrega el elemento de control de la transacción actual a la url generada</td>
</tr>
<tr>
<td>paramId</td>
<td>Indica el nombre del parámetro que se agrega a la url</td>
</tr>
<tr>
<td>paramName</td>
<td>Valor para el parámetro obtenido desde el bean llamado paramName</td>
</tr>
<tr>
<td>paramProperty</td>
<td>El nombre de la propiedad del bean indicado por  paramName que devuelve el valor del parámetro</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/05/27/struts-logic-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Struts bean tags</title>
		<link>http://www.railsymas.com/2011/05/25/struts-bean-tags/</link>
		<comments>http://www.railsymas.com/2011/05/25/struts-bean-tags/#comments</comments>
		<pubDate>Wed, 25 May 2011 22:06:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2238</guid>
		<description><![CDATA[En los múltiples ejemplos mostrados hemos utilizado diferentes etiquetas de struts correspondientes a la librería bean En el siguiente cuadro al igual que hacíamos con las etiquetas html de struts pondremos una colección de etiquetas de la librería bean de struts Dentro de una página jsp declaramos la siguiente línea de texto para la importación [...]]]></description>
			<content:encoded><![CDATA[<p> En los múltiples ejemplos mostrados hemos utilizado diferentes etiquetas de struts correspondientes a la librería bean</p>
<p><span id="more-2238"></span></p>
<p>En el siguiente cuadro al igual que hacíamos con las etiquetas html de struts pondremos una colección de etiquetas de la librería bean de struts</p>
<p>Dentro de una página jsp declaramos la siguiente línea de texto para la importación de la librería bean</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-bean&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bean&quot;</span> <span style="color: #339933;">%&gt;</span></pre></div></div>

<p><br/></p>
<table border="1" caption="listado de struts bean tags">
<tr>
<td>message</td>
<td> Imprime una cadena de texto obtenida del fichero de idiomas</td>
</tr>
<tr>
<td>write</td>
<td> Muestra en pantalla la información obtenida de un bean</td>
</tr>
<tr>
<td>define</td>
<td>Permite crear una variable a partir de un bean existente</td>
</tr>
</table>
<p><br/></p>
<p><strong>propiedades para message</strong></p>
<table border="1" caption="propiedades para message">
<tr>
<td>arg0 , arg1, arg2 ,arg3 etc</td>
<td> Indica el valor para {0} {1} {2} {3} en la cadena del idioma</td>
</tr>
<tr>
<td>key</td>
<td>Indica una clave del mensaje solicitado en los recursos del idioma</td>
</tr>
<tr>
<td>property</td>
<td>Indica la propiedad del bean que será usada </td>
</tr>
<tr>
<td>name</td>
<td>Indica el nombre del bean cuya propiedad es accedida especificada en property</td>
</tr>
<tr>
<td>bundle</td>
<td>Nombre de atributo de aplicación bajo el cuál se guarda el objeto MessageResources </td>
</tr>
<tr>
<td>scope</td>
<td>Indica la accesibilidad del bean especificado por el name </td>
</tr>
</table>
<p><br/></p>
<p><strong>propiedades para write </strong></p>
<table border="1" caption="listado de propiedades write">
<tr>
<td>ignore</td>
<td> Si es true el bean indicado por name y scope no existe, si es false lanza excepción</td>
</tr>
<tr>
<td>property</td>
<td> Indica el nombre de la propiedad del bean name que será usuada </td>
</tr>
<tr>
<td>scope</td>
<td>Indica la accesibilidad del bean especificado por el name </td>
</tr>
<tr>
<td>format</td>
<td>Indica la cadena usada para convertir un bean o un valor de una propiedad string </td>
</tr>
<tr>
<td>formatKey</td>
<td>Indica la clave que será usada para buscar una cadena de formato de recursos</td>
</tr>
</table>
<p><br/></p>
<p><strong>propiedades de define</strong></p>
<table border="1" caption="listado de propieades define">
<tr>
<td>name</td>
<td>Indica el nombre del bean cuya propiedad es accedida en el caso de utilizar property</td>
</tr>
<tr>
<td>property</td>
<td>Indica el nombre de la propiedad del bean name que será usada,puede ser una propiedad indexada o una expresión </td>
</tr>
<tr>
<td>scope</td>
<td>indica la visibilidad en la que se construye el nuevo bean usando las reglas pageContext.findAttribute()</td>
</tr>
<tr>
<td>toScope</td>
<td>Indica la visibilidad en la que se construye el bean por defecto es sessión </td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/05/25/struts-bean-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modificando datos struts hibernate</title>
		<link>http://www.railsymas.com/2011/04/20/modificando-datos-struts-hibernate/</link>
		<comments>http://www.railsymas.com/2011/04/20/modificando-datos-struts-hibernate/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 13:24:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=2213</guid>
		<description><![CDATA[Ejemplo para la modificación de datos almacenados en una tabla mediante hibernate y struts. Una vez insertados los datos en la base de datos podemos es común tener que modificarlos por requisitos del usuario de la aplicación Basándonos en el anterior ejemplo de integración de struts con hibernate enlace integración-struts-hibernate/ Creamos una clase controlador que [...]]]></description>
			<content:encoded><![CDATA[<p>Ejemplo para la modificación de datos almacenados en una tabla mediante hibernate y struts.</p>
<p><span id="more-2213"></span></p>
<p>Una vez insertados los datos en la base de datos podemos es común tener que modificarlos por requisitos del usuario de la aplicación</p>
<p>Basándonos en el anterior ejemplo de integración de struts con hibernate enlace <a href="http://www.railsymas.com/2010/06/25/integracion-struts-hibernate/">integración-struts-hibernate/</a></p>
<p>Creamos una clase controlador que tienen como objetivo modificar un campo de una base de dastos buscándolo por el id correspondiente del registro para luego modificar el campo </p>
<p>Para ello hacemos uso del dispatchaction también explicado en este sitio, se presenta un formulario con la posibilidad de modificar cualquier campo de cualquier registro de la tabla</p>
<p>Configuración para el desarrollo del ejemplo como ya se explicó, en los anteriores ejemplos para la categoría de struts</p>
<p>Declaración del bean dinámico</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- ================================================ Form Bean Definitions --&gt;</span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernatelibrocambio&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.struts.action.DynaActionForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;libro_id&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.Integer&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autor&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tematica&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Declaración de las acciones</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/modificacion&quot;</span>         </span>
<span style="color: #009900;">         <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;acciones.AccionDispatchHibernateModificacion&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;request&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernatelibrocambio&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">validate</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">parameter</span>=<span style="color: #ff0000;">&quot;method&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;/pages/jsphibernate/modificaciones.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span> 
&nbsp;
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set-property</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;cancellable&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cancelada&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/pages/cancelada2.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;listado&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/pages/listadohibernate.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>       
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span></span></pre></td></tr></table></div>

<p>Declaración de AccionDispatchHibernateModificacion</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">acciones</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.actions.DispatchAction</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionForm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionForward</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionMapping</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.DynaActionForm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.Transaction</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.SessionFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">configuracion.plugin.HibernatePlugin</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.TransactionException</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AccionDispatchHibernateModificacion <span style="color: #000000; font-weight: bold;">extends</span> DispatchAction <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
    	<span style="color: #000000; font-weight: bold;">private</span> ActionForward reenvio <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> titulo<span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> autor<span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> tematica<span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> DynaActionForm formulario<span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">Integer</span> id<span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> Session sesion<span style="color: #339933;">;</span>
    	<span style="color: #000000; font-weight: bold;">private</span> Transaction transaccion <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> Session obtenerSesion <span style="color: #009900;">&#40;</span>HttpServletRequest request<span style="color: #009900;">&#41;</span> 
        <span style="color: #009900;">&#123;</span>   
&nbsp;
        	ServletContext contexto <span style="color: #339933;">=</span> request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        	SessionFactory factory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SessionFactory<span style="color: #009900;">&#41;</span> contexto.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span>HibernatePlugin.<span style="color: #006633;">clave_hibernate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
        	<span style="color: #000000; font-weight: bold;">return</span> factory.<span style="color: #006633;">openSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> listado <span style="color: #009900;">&#40;</span>Session sesion , HttpServletRequest request<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
           	<span style="color: #000000; font-weight: bold;">try</span>
           	<span style="color: #009900;">&#123;</span>
           		transaccion <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           		<span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Libros<span style="color: #339933;">&gt;</span> libros <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Libros&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           		request.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libros&quot;</span>, libros<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
           		transaccion.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           	<span style="color: #009900;">&#125;</span>
           	<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransactionException e<span style="color: #009900;">&#41;</span>
           	<span style="color: #009900;">&#123;</span>
           		transaccion.<span style="color: #006633;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           		e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">public</span> ActionForward MoficarTitulo <span style="color: #009900;">&#40;</span>ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    	<span style="color: #009900;">&#123;</span>
&nbsp;
    		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> isCancelled<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span>
    			reenvio <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cancelada&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    		<span style="color: #009900;">&#125;</span>
    		<span style="color: #000000; font-weight: bold;">else</span>
    		<span style="color: #009900;">&#123;</span> 
&nbsp;
    			formulario <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DynaActionForm<span style="color: #009900;">&#41;</span> form<span style="color: #339933;">;</span> 
&nbsp;
    			id<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span>formulario.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libro_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
    		    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sesion</span> <span style="color: #339933;">=</span> obtenerSesion<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
    			<span style="color: #000000; font-weight: bold;">try</span>
    			<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
    			 transaccion <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    			 Libros libro <span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Libros<span style="color: #009900;">&#41;</span> sesion.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Libros.<span style="color: #000000; font-weight: bold;">class</span>, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    			 libro.<span style="color: #006633;">setTitulo</span><span style="color: #009900;">&#40;</span>formulario.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    			 transaccion.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
    			 listado<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sesion</span>,request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 				 <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">reenvio</span> <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    			<span style="color: #009900;">&#125;</span>
    			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransactionException e<span style="color: #009900;">&#41;</span>
    			<span style="color: #009900;">&#123;</span>
    				transaccion.<span style="color: #006633;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    			<span style="color: #009900;">&#125;</span>
    			<span style="color: #000000; font-weight: bold;">finally</span>
               	<span style="color: #009900;">&#123;</span>
               		sesion.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
    		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
    		<span style="color: #000000; font-weight: bold;">return</span> reenvio<span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #009900;">&#125;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">public</span> ActionForward ModificarAutor<span style="color: #009900;">&#40;</span>ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isCancelled<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span> 
    			reenvio <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cancelada&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    		<span style="color: #009900;">&#125;</span>
    		<span style="color: #000000; font-weight: bold;">else</span>
    		<span style="color: #009900;">&#123;</span> 
&nbsp;
    			formulario <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DynaActionForm<span style="color: #009900;">&#41;</span> form<span style="color: #339933;">;</span> 
&nbsp;
    			id<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span>formulario.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libro_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    		    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sesion</span> <span style="color: #339933;">=</span> obtenerSesion<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
    			<span style="color: #000000; font-weight: bold;">try</span>
    			<span style="color: #009900;">&#123;</span> 
&nbsp;
       			 transaccion <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
       			 Libros libro <span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Libros<span style="color: #009900;">&#41;</span> sesion.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Libros.<span style="color: #000000; font-weight: bold;">class</span>, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       			 libro.<span style="color: #006633;">setAutor</span><span style="color: #009900;">&#40;</span>formulario.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       			 transaccion.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
       			 listado<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sesion</span>,request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    			 <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">reenvio</span> <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    			<span style="color: #009900;">&#125;</span>
    			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransactionException e<span style="color: #009900;">&#41;</span>
    			<span style="color: #009900;">&#123;</span>
    				transaccion.<span style="color: #006633;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    			<span style="color: #009900;">&#125;</span>
    			<span style="color: #000000; font-weight: bold;">finally</span>
    			<span style="color: #009900;">&#123;</span>
    				sesion.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    			<span style="color: #009900;">&#125;</span>
&nbsp;
    		<span style="color: #009900;">&#125;</span>
&nbsp;
    		<span style="color: #000000; font-weight: bold;">return</span> reenvio<span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">public</span> ActionForward ElimarTematica<span style="color: #009900;">&#40;</span>ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isCancelled<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span>
    			reenvio <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cancelada&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #009900;">&#125;</span>
    		<span style="color: #000000; font-weight: bold;">else</span>
    		<span style="color: #009900;">&#123;</span> 
&nbsp;
    			formulario <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DynaActionForm<span style="color: #009900;">&#41;</span> form<span style="color: #339933;">;</span> 
&nbsp;
    			id<span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span>formulario.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libro_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    		    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sesion</span> <span style="color: #339933;">=</span> obtenerSesion<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
    			<span style="color: #000000; font-weight: bold;">try</span>
    			<span style="color: #009900;">&#123;</span>
&nbsp;
    			    transaccion <span style="color: #339933;">=</span>	sesion.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    			    Libros libro <span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Libros<span style="color: #009900;">&#41;</span> sesion.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Libros.<span style="color: #000000; font-weight: bold;">class</span>, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    			    sesion.<span style="color: #006633;">delete</span><span style="color: #009900;">&#40;</span>libro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    			    transaccion.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
&nbsp;
    			    listado<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sesion</span>,request<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       			    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">reenvio</span> <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    			<span style="color: #009900;">&#125;</span>
    			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransactionException e <span style="color: #009900;">&#41;</span>
    			<span style="color: #009900;">&#123;</span>
    				transaccion.<span style="color: #006633;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    			<span style="color: #009900;">&#125;</span>
    			<span style="color: #000000; font-weight: bold;">finally</span>
    			<span style="color: #009900;">&#123;</span>
    				sesion.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    			<span style="color: #009900;">&#125;</span>
&nbsp;
    		<span style="color: #009900;">&#125;</span>
&nbsp;
    		<span style="color: #000000; font-weight: bold;">return</span> reenvio<span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>salida por pantalla de consola</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">INFO<span style="color: #00AA00;">:</span> Tiles definition factory found for request processor <span style="color: #ff0000;">''</span>.
Hibernate<span style="color: #00AA00;">:</span> 
    select
        libros0_<span style="color: #6666ff;">.id</span> as id0_0_<span style="color: #00AA00;">,</span>
        libros0_<span style="color: #6666ff;">.titulo</span> as titulo0_0_<span style="color: #00AA00;">,</span>
        libros0_<span style="color: #6666ff;">.autor</span> as autor0_0_<span style="color: #00AA00;">,</span>
        libros0_<span style="color: #6666ff;">.tematica</span> as tematica0_0_ 
    from
        libros_jdbc<span style="color: #6666ff;">.libros</span> libros0_ 
    where
        libros0_.id<span style="color: #00AA00;">=</span>?
Hibernate<span style="color: #00AA00;">:</span> 
    update
        libros_jdbc.libros 
    set
        titulo<span style="color: #00AA00;">=</span>?<span style="color: #00AA00;">,</span>
        autor<span style="color: #00AA00;">=</span>?<span style="color: #00AA00;">,</span>
        tematica<span style="color: #00AA00;">=</span>? 
    where
        id<span style="color: #00AA00;">=</span>?
Hibernate<span style="color: #00AA00;">:</span> 
    select
        libros0_<span style="color: #6666ff;">.id</span> as id0_<span style="color: #00AA00;">,</span>
        libros0_<span style="color: #6666ff;">.titulo</span> as titulo0_<span style="color: #00AA00;">,</span>
        libros0_<span style="color: #6666ff;">.autor</span> as autor0_<span style="color: #00AA00;">,</span>
        libros0_<span style="color: #6666ff;">.tematica</span> as tematica0_ 
    from
        libros_jdbc<span style="color: #6666ff;">.libros</span> libros0_</pre></td></tr></table></div>

<p><img src="http://www.railsymas.com/wp-content/uploads/2011/04/modifi.png" alt="" title="modifi" width="614" height="310" class="alignnone size-full wp-image-2235" /><br />
resultado<br />
<img src="http://www.railsymas.com/wp-content/uploads/2011/04/modifi2.png" alt="" title="modifi2" width="603" height="232" class="alignnone size-full wp-image-2236" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2011/04/20/modificando-datos-struts-hibernate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pruebas con el fichero de configuración de hibernate</title>
		<link>http://www.railsymas.com/2010/12/17/pruebas-con-el-fichero-de-configuracion-de-hibernate/</link>
		<comments>http://www.railsymas.com/2010/12/17/pruebas-con-el-fichero-de-configuracion-de-hibernate/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 11:55:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1953</guid>
		<description><![CDATA[Cuando estamos desarrollando un proyecto con hibernate, pasamos como en todo desarrollo de software por un proceso de pruebas en el que introducimos diferentes datos simplemente para ir viendo la evolución de los diferentes requisitos de nuestra aplicación. con 1 2 3 4 5 6 7 8 9 &#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62; &#60;!DOCTYPE hibernate-configuration PUBLIC &#34;-//Hibernate/Hibernate [...]]]></description>
			<content:encoded><![CDATA[<p> Cuando estamos desarrollando un proyecto con hibernate, pasamos como en todo desarrollo  de software por un proceso de pruebas en el que introducimos diferentes datos simplemente para ir viendo la evolución de los diferentes requisitos de nuestra aplicación.</p>
<p> <span id="more-1953"></span></p>
<p> con</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE hibernate<span style="color: #339933;">-</span>configuration <span style="color: #000000; font-weight: bold;">PUBLIC</span>
		<span style="color: #0000ff;">&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;</span>
		<span style="color: #0000ff;">&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>hibernate<span style="color: #339933;">-</span>configuration<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>session<span style="color: #339933;">-</span>factory<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.hbm2ddl.auto&quot;</span><span style="color: #339933;">&gt;</span>create<span style="color: #339933;">&lt;/</span>property<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>session<span style="color: #339933;">-</span>factory<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>hibernate<span style="color: #339933;">-</span>configuration<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>con la propiedad hibernate.hbm2ddl.auto con el valor create, cada vez que ejecutamos la aplicación nos limpia la base de datos para introducir nuevos valores. Si queremos mantener los datos utilizamos el valor update</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/12/17/pruebas-con-el-fichero-de-configuracion-de-hibernate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Integración Struts hibernate</title>
		<link>http://www.railsymas.com/2010/06/25/integracion-struts-hibernate/</link>
		<comments>http://www.railsymas.com/2010/06/25/integracion-struts-hibernate/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 18:14:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1663</guid>
		<description><![CDATA[En este ejemplo se inserta un tupla en la base de datos creada, con los datos introducidos mediante un formulario rellenado por el usuario Tenemos la tabla libros de la base de datos libros_jdbc, tal como viene en este ejemplo base de datos. Tenemos una tabla libros pertenecientes a la base datos con tres campos [...]]]></description>
			<content:encoded><![CDATA[<p>   En este ejemplo se inserta un tupla en la base de datos creada, con los datos introducidos mediante un formulario rellenado por el usuario</p>
<p>  <span id="more-1663"></span></p>
<p>  Tenemos la tabla libros de la base de datos libros_jdbc, tal como viene en este ejemplo <a href="http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/">base de datos</a>. Tenemos una tabla libros pertenecientes a la base datos con tres campos  el titulo, autor y la temática del libro.</p>
<p>Para este ejemplo necesitamos para un mejor entendimiento necesitamos conocer como se crea un plugin y aquí tenemos uno hecho <a href="http://www.railsymas.com/2010/05/23/creacion-de-un-plugin-con-struts-xml-dom/">creación de plugin</a></p>
<p> Formulario de recogida de datos <a href="http://www.railsymas.com/wp-content/uploads/2010/06/formulahiber.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/formulahiber.png" alt="" title="formulahiber" width="580" height="280" class="alignnone size-full wp-image-1668" /></a></p>
<p>este formumario esta asociado a una acción recogida en el fichero de configuración de struts el struts-config.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span></span>
&nbsp;
<span style="color: #009900;">          <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/formularioHibernate&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;acciones.AccionHibernateLibro&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;request&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernatelibro&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">validate</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;/pages/formulariohibernate.jsp&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000000; font-weight: bold;">&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set-property</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;cancellable&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;listado&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/pages/listadohibernate.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cancelada&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/pages/cancelada2.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Se ha explicado en otros post anteriores cada uno de los elementos que aparecen en  esta configuración, pero a modo de recordatorio, se enumeran los valores de los diferentes campos. Para el path tenemos el nombre de la acción que se  ejecuta en este caso (formulariohibernate), esta acción esta recogida en una clase (AccionHibernateLibro) que es la encargada de evaluar y procesar los datos, el name hace referencia al bean en este caso dinámico encargado de recoger los datos del formulario (hibernatelibro).</p>
<p>Código del bean dinámico encargado de recoger los datos del formulario, para poder ser tratados por la clase (AcciónHibernateLibro)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernatelibro&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.struts.validator.DynaValidatorForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tematica&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autor&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Código del formulario formulariohibernate.jsp correspondiente a la imagen anterior</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>  pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-html&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;html&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-bean&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bean&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>base<span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo.hibernate&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo.hibernate&quot;</span><span style="color: #339933;">/&gt;&lt;/</span>h2<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;errores&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>errors<span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;imagen&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>img srcKey<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro.imagen&quot;</span> titleKey<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;libro.imagen.alt&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenido&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>form method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formularioHibernate&quot;</span> styleId<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulario&quot;</span> focus<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo&quot;</span> <span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulariodatasource.titulolibro&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>text property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulariodatasource.autor&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>text property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulariodatasource.tematica&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>text property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>submit styleClass<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>cancel styleClass<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cancelar&quot;</span><span style="color: #339933;">/&gt;</span>
   <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>reset  styleClass<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;borrar&quot;</span><span style="color: #339933;">/&gt;</span> 
&nbsp;
&nbsp;
   <span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span> www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span> <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>configuración del plugin en el fichero  struts-config.xml, creamos un plugin indicando la clase HibernatePlugin y la propiedad dirección con el valor de la ruta del fichero de configuración de hibernate</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #808080; font-style: italic;">&lt;!-- ========== Hibernate ======= --&gt;</span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plug-in</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;configuracion.plugin.HibernatePlugin&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set-property</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;direccion&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/hibernate.cfg.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plug-in<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>para cargar el fichero de configuración de hibernate creamos un plugin, como repaso tenemos que extender de la clase Plugin y sobre escribimos los métodos destroy e init. Se crea por comodidad una variable estática de la clase llamada clave_hibernate que nos permitirá recoger la factoria de hibernate para poder insertar, borrar, editar etc..</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">configuracion.plugin</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.SessionFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.cfg.Configuration</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionServlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.PlugIn</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.config.ModuleConfig</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.HibernateException</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HibernatePlugin <span style="color: #000000; font-weight: bold;">implements</span> PlugIn
 <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> direccion<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> clave_hibernate <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hibernate&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> SessionFactory factoria <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> direccion<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDireccion<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> direccion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">direccion</span> <span style="color: #339933;">=</span> direccion<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">try</span>
     <span style="color: #009900;">&#123;</span>
       factoria.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>HibernateException e<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No se puede cerrar la sesión: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>ActionServlet servlet, ModuleConfig config<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException
  <span style="color: #009900;">&#123;</span>
        Configuration configuration <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        ServletContext contexto <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
&nbsp;
          contexto <span style="color: #339933;">=</span> servlet.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          configuration <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Configuration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span>direccion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          factoria <span style="color: #339933;">=</span> configuration.<span style="color: #006633;">buildSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          contexto.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>clave_hibernate, factoria<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>HibernateException e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error de inicialización de hibernate: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>código de la clase encargada de recoger la acción, esta clase como solamente realiza una acción extendemos de action y editamos el método ejecute. Esta clase es la encargada de recoger los datos del formulario así como de la utilización de recuperar el manejador de la factoria.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">acciones</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.Action</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionMapping</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionForm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.validator.DynaValidatorForm</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionForward</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">configuracion.plugin.HibernatePlugin</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.SessionFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.Transaction</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.TransactionException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">modelos.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AccionHibernateLibro <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Action</span> <span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> ActionForward reenvio <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> DynaValidatorForm formulario <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Session sesion <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> SessionFactory  factory<span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Transaction transaction <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> ActionForward execute <span style="color: #009900;">&#40;</span>ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
	<span style="color: #009900;">&#123;</span>   
&nbsp;
&nbsp;
		formulario <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DynaValidatorForm<span style="color: #009900;">&#41;</span> form<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isCancelled<span style="color: #009900;">&#40;</span>request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			reenvio <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cancelada&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>   
		    ServletContext context <span style="color: #339933;">=</span> request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		    factory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SessionFactory<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span>HibernatePlugin.<span style="color: #006633;">clave_hibernate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			sesion <span style="color: #339933;">=</span>  factory.<span style="color: #006633;">openSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">try</span>
			<span style="color: #009900;">&#123;</span> 
				transaction <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				Libros libro <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Libros<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">//introducimos los valores para el libro nuevo</span>
				libro.<span style="color: #006633;">setTitulo</span><span style="color: #009900;">&#40;</span>formulario.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				libro.<span style="color: #006633;">setAutor</span><span style="color: #009900;">&#40;</span>formulario.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				libro.<span style="color: #006633;">setTematica</span><span style="color: #009900;">&#40;</span>formulario.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
				sesion.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>libro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						
				transaction.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				transaction <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Libros<span style="color: #339933;">&gt;</span> libros <span style="color: #339933;">=</span>  sesion.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from Libros&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">Iterator</span> <span style="color: #339933;">&lt;</span>Libros<span style="color: #339933;">&gt;</span> iterador <span style="color: #339933;">=</span> libros.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> iterador.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					 libro <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Libros<span style="color: #009900;">&#41;</span> iterador.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;titulo:&quot;</span><span style="color: #339933;">+</span>libro.<span style="color: #006633;">getTitulo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autor:&quot;</span><span style="color: #339933;">+</span>libro.<span style="color: #006633;">getAutor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tematica:&quot;</span><span style="color: #339933;">+</span>libro.<span style="color: #006633;">getTematica</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
				<span style="color: #009900;">&#125;</span>
&nbsp;
				transaction.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			    request.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;libros&quot;</span>, libros<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			    reenvio <span style="color: #339933;">=</span> mapping.<span style="color: #006633;">findForward</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;listado&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransactionException e  <span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span> 
&nbsp;
				<span style="color: #666666; font-style: italic;">//abortamos la transacción y restauramos los valores anteriores</span>
				transaction.<span style="color: #006633;">rollback</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			    e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
&nbsp;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">finally</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">//cerramos la sesión</span>
				sesion.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> reenvio<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>archivo de configuración hibernate.cfg,xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-configuration PUBLIC</span>
<span style="color: #00bbdd;">		&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;</span>
<span style="color: #00bbdd;">		&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-factory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.driver_class&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>com.mysql.jdbc.Driver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.username&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.password&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.url&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> jdbc:mysql://localhost:3306/libros_jdbc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>org.hibernate.dialect.MySQL5Dialect<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.hbm2ddl.auto&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>update<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;show_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;format_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;modelos/Libros.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>       
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-factory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>sobre los parámetros recogidos en el fichero hibernate.cfg.xml se comentaron en el post <a href="http://www.railsymas.com/2010/06/16/hibernate-tools-para-eclipse/">hibernate tools</a></p>
<p>Para el mapeo de las tablas tenemos que crear un archivo xml con extension hbm.xml. estos archivos los podemos poner en un package propio por en este ejemplo &#8220;modelo&#8221; haciendo referencia a las las clases y ficheros de configuración asociados a las tablas de la base de datos.</p>
<p>Al ejecutar la aplicación se nos crea automáticamente una clase bean con los propiedades indicadas en los ficheros hbm.xml, en este caso una clase Libro</p>
<p>Para crear un fichero hbm vamos con la vista hibernate de eclipse activada a new, hibernate xml mapping creamos un fichero libros.hbm.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- Generated 26-ene-2010 1:33:06 by Hibernate Tools 3.2.4.GA --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;modelos.Libros&quot;</span> <span style="color: #000066;">table</span>=<span style="color: #ff0000;">&quot;libros&quot;</span> <span style="color: #000066;">catalog</span>=<span style="color: #ff0000;">&quot;libros_jdbc&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.Integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;generator</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;identity&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;titulo&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autor&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;autor&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tematica&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tematica&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">not-null</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Valores de los parámetros, table hace referencia a la tabla de la base de datos, catalog hace referencia a la base de datos, el primer parametro id indicamos que el campo es la clave primaria, los atributos property indicamos el nombre de la propiedad y a que campo de la tabla corresponde es decir podemos tener el campo titulo en la tabla y en la propiedad  titu_x por decir algo, entoces a la hora de usar por código el objeto de mapeo haríamos objeto.titu_x pero por comodidad le damos el mismo valor que la tabla así es más fácil acordorse de las propiedades. </p>
<p>Imagen del listado del libro una vez guardado los datos </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/listadohibernateli.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/listadohibernateli.png" alt="" title="listadohibernateli" width="580" height="210" class="alignnone size-full wp-image-1690" /></a></p>
<p>Salida por pantalla para verificar la inserción como consecuencia de activar en el fichero hibernate.cfg.xml el parámetro show_sql y format_sql</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">INFO: Tiles definition factory found for request processor ''.
Hibernate: 
    insert 
    into
        libros_jdbc.libros
        (titulo, autor, tematica) 
    values
        (?, ?, ?)
Hibernate: 
    select
        libros0_.id as id0_,
        libros0_.titulo as titulo0_,
        libros0_.autor as autor0_,
        libros0_.tematica as tematica0_ 
    from
        libros_jdbc.libros libros0_
titulo:titulo3
autor:autor3
tematica:tematica3</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/06/25/integracion-struts-hibernate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hibernate  tools para eclipse</title>
		<link>http://www.railsymas.com/2010/06/16/hibernate-tools-para-eclipse/</link>
		<comments>http://www.railsymas.com/2010/06/16/hibernate-tools-para-eclipse/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 20:17:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Nuevas Tecnologías]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1621</guid>
		<description><![CDATA[Hibernate es el principal orm (herramienta de mapeo objeto relacional) para las aplicaciones java, no es el único y junto con ibatis Hibernate facilita el mapeo entre una base de datos y el modelo de objetos de una aplicación, su configuración se realiza mediante archivos xml, aunque también se puede trabajar con jpa (anatociones). Hibernate [...]]]></description>
			<content:encoded><![CDATA[<p>  Hibernate es el principal orm (herramienta de mapeo objeto relacional) para las aplicaciones java, no es el único y junto con ibatis </p>
<p><span id="more-1621"></span></p>
<p>Hibernate facilita el mapeo entre una base de datos y el modelo de objetos de una aplicación, su configuración se realiza mediante archivos xml, aunque también se puede trabajar con jpa (anatociones).</p>
<p>Hibernate permite gestionar bases de datos, trabajar con bases de datos relacionales de una forma rápida recuperando objetos de las consultas para poder aplicar la lógica de negocio.</p>
<p>Eclipse dispone de un plugin que nos permite trabajar más comodamente con los archivos implicados en el trabajo con hibernate.</p>
<p>El plugin se denomina Hibernate tools y para la versión de eclipse galileo se recomienda </p>
<p> Dirección web</p>
<p>https://www.jboss.org/tools/download/stable/3_1_GA.html</p>
<p>Para una mejor referencia teórica puramente de hibernate el siguiente enlace ofrece gran ayuda <a href="http://www.davidmarco.es/tutoriales/hibernate-reference/">/www.davidmarco.es/tutoriales/hibernate-reference</a></p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/hiberplugins.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/hiberplugins.png" alt="" title="hiberplugins" width="350" height="127" class="alignnone size-full wp-image-1631" /></a></p>
<p>Descargamos los los archivos correspondientes del archivo descargado en los directorios plugins y features del eclipse </p>
<p> para cargar el plugin en linux  dentro del directorio de eclipse galileo ./eclipse -clean y en windows sólo eclipse -clean<a href="http://www.railsymas.com/wp-content/uploads/2010/06/hiberxml.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/hiberxml.png" alt="" title="hiberxml" width="561" height="130" class="alignnone size-full wp-image-1635" /></a></p>
<p>Si vamos a file, new , other y nos aparece la pantalla anterior donde podemos observar como se puede elegir entre los diferentes archivos de configuración de hibernate.</p>
<p>Podemos activar la vista de hibernate, como siempre, window, open perspective , other, hibernate, así se abren unas series de ventanas de consulta y configuración</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/perhibernate.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/perhibernate.png" alt="" title="perhibernate" width="147" height="42" class="alignnone size-full wp-image-1640" /></a></p>
<p>Una vez en la perspectiva de hibernate, hacemos file , new , hibernate Configuration file<br />
<a href="http://www.railsymas.com/wp-content/uploads/2010/06/confighibern.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/confighibern.png" alt="" title="confighibern" width="538" height="463" class="alignnone size-full wp-image-1642" /></a></p>
<p>Se hace referencia en el contenedor al proyecto donde estará el archivo de configuración, el nombre del archivo puede ser cualquiera, pero por defecto es hibernate.cgf.xml,</p>
<p>Se introducen los datos correspondientes al nombre de usuario y clave de la base de datos.<br />
Se indica el tipo de driver  a utilizar y el url a  la base de datos, en este caso para mysql</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-configuration PUBLIC</span>
<span style="color: #00bbdd;">		&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;</span>
<span style="color: #00bbdd;">		&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-factory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.driver_class&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>com.mysql.jdbc.Driver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.username&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.password&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.connection.url&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> jdbc:mysql://localhost:3306/libros_jdbc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.dialect&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>org.hibernate.dialect.MySQL5Dialect<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hibernate.hbm2ddl.auto&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>update<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;show_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;format_sql&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;modelos/Libros.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>       
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;modelos/Estudiante.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;modelos/Direccion.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-factory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p> En este archivo de configuración principal se indican donde estan ubicados los ficheros de mapeo hbm.xml a las tablas de la base de datos en este caso al package modelos.</p>
<p>  mapping resource=&#8221;modelos/Libros.hbm.xml&#8221;</p>
<p> vemos la correspondencia con los archivos de mapeo </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/modeloshiber.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/modeloshiber.png" alt="" title="modeloshiber" width="240" height="180" class="alignnone size-full wp-image-1656" /></a></p>
<p>Consola de configuración de hibernate donde indicamos el proyecto, así como la ubicación del fichero de configuración de hibernate</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/consolahiber1.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/consolahiber1.png" alt="" title="consolahiber" width="580" height="480" class="alignnone size-full wp-image-1658" /></a></p>
<p>los valores de hibernate.hbm2ddl.auto son create que destruye las tablas de la base de datos y crea unas nuevas cada vez que ejecutamos la aplicación, update que no destruimos las tablas al arracan la aplicación y nos permite la modificación de los datos almacenados, validate valida el esquema y no hace cambios en la base de datos y create-drop el limina el esquema al final de la sesión</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/06/16/hibernate-tools-para-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creación de un plugin con struts xml dom</title>
		<link>http://www.railsymas.com/2010/05/23/creacion-de-un-plugin-con-struts-xml-dom/</link>
		<comments>http://www.railsymas.com/2010/05/23/creacion-de-un-plugin-con-struts-xml-dom/#comments</comments>
		<pubDate>Sun, 23 May 2010 10:04:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1474</guid>
		<description><![CDATA[Tutorial de struts para la creación de un plugin en struts Struts nos permite la creación de plugins propios, en los diferentes post utilizabamos plugins standard como struts-validator y struts-tiles. Pero también se pueden crear plugins a medida de nuestras necesidades Tenemos un fichero xml, donde tenemos una estructura un elemento nodo raiz llamado plantilla [...]]]></description>
			<content:encoded><![CDATA[<p>Tutorial de struts para la creación de un plugin en struts<br />
<span id="more-1474"></span></p>
<p>Struts nos permite la creación de plugins propios, en los diferentes post utilizabamos plugins standard como struts-validator y struts-tiles. Pero también se pueden crear plugins a medida de nuestras necesidades</p>
<p>Tenemos un fichero xml, donde tenemos una estructura un elemento nodo raiz llamado plantilla y una serie de nodos hijos llamados obrero, cada elemento hijo consta de un atributo nombre y dos elementos subhijos cargo y edad</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plantilla<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;obrero</span> <span style="color: #000066;">nombre</span>=<span style="color: #ff0000;">&quot;pepe&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cargo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>peón<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cargo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;edad<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>25<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/edad<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/obrero<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;obrero</span> <span style="color: #000066;">nombre</span>=<span style="color: #ff0000;">&quot;juan&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cargo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>capataz<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cargo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;edad<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>46<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/edad<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/obrero<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;obrero</span> <span style="color: #000066;">nombre</span>=<span style="color: #ff0000;">&quot;maria&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cargo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pintor<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cargo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;edad<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>38<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/edad<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/obrero<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plantilla<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Este fichero xml  lo denominamos plantillas.xml y será el fichero que lea el plugin de struts.</p>
<p>Para la creación del plugin debemos de declararlo en el fichero struts-config.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- =============================================== Plug Ins Configuration --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plug-in</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;acciones.PluginEjemplo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set-property</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;direccion&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/plantilla.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plug-in<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Por un lado tenemos el nombre el de la clase del plugin,  en el valor del atributo className  y por otro el valor de la propiedad dirección en el que indicamos la ruta a la dirección del fichero xml </p>
<p>La clase que implementa la interface Plugin, debe implementar los métodos init y destroy, si se pasan parámetros en la declaración del plugin en este caso dirección con el valor de la ruta al fichero para poder asignar valor y recuperar desde la clase del plugin es necesario crear métodos getter y setter</p>
<p>El resto de los métodos son los encargados de leer el fichero xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">acciones</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletContext</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.PlugIn</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.action.ActionServlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.struts.config.ModuleConfig</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.parsers.DocumentBuilderFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.w3c.dom.Document</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.w3c.dom.Element</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.w3c.dom.Node</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.w3c.dom.NodeList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.xml.sax.SAXException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.parsers.DocumentBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.xml.parsers.ParserConfigurationException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">vo.Obrero</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span>  <span style="color: #000000; font-weight: bold;">class</span> PluginEjemplo <span style="color: #000000; font-weight: bold;">implements</span> PlugIn
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> nombreclase <span style="color: #339933;">=</span> PluginEjemplo.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> direccion<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #003399;">Document</span> documento<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> ArrayList<span style="color: #339933;">&lt;</span>Obrero<span style="color: #339933;">&gt;</span> listadoObreros <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Obrero<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> direccion<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setDireccion<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> direccion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">direccion</span> <span style="color: #339933;">=</span> direccion<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init <span style="color: #009900;">&#40;</span>ActionServlet servlet, ModuleConfig config<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException
	<span style="color: #009900;">&#123;</span>
&nbsp;
		ServletContext  contexto <span style="color: #339933;">=</span> servlet.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>nombreclase<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;direccion:&quot;</span><span style="color: #339933;">+</span>getDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		PluginEjemplo pluginejemplo <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PluginEjemplo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		leerXml <span style="color: #009900;">&#40;</span>getDireccion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,servlet<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		contexto.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>nombreclase,pluginejemplo <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span>  <span style="color: #000066; font-weight: bold;">void</span> leerXml<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> direccion, ActionServlet servlet<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		DocumentBuilderFactory factoria <span style="color: #339933;">=</span> DocumentBuilderFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
           DocumentBuilder constructor <span style="color: #339933;">=</span> factoria.<span style="color: #006633;">newDocumentBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           ServletContext contexto <span style="color: #339933;">=</span> servlet.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>           
           <span style="color: #003399;">String</span> lugar <span style="color: #339933;">=</span> contexto.<span style="color: #006633;">getRealPath</span><span style="color: #009900;">&#40;</span>direccion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
           documento <span style="color: #339933;">=</span> constructor.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>lugar<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           documento.<span style="color: #006633;">getDocumentElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">normalize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           Node nodoraiz <span style="color: #339933;">=</span> documento.<span style="color: #006633;">getDocumentElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>          
           <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Obrero<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>nodoraiz.<span style="color: #006633;">getNodeName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
           nodos<span style="color: #009900;">&#40;</span>documento<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ParserConfigurationException ex<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;no se puede crear el Dom parser:&quot;</span><span style="color: #339933;">+</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>SAXException ex<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Generar Sax excepción: &quot;</span><span style="color: #339933;">+</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> ex<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
		  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Io excepción: &quot;</span><span style="color: #339933;">+</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000066; font-weight: bold;">void</span> nodos <span style="color: #009900;">&#40;</span><span style="color: #003399;">Document</span> documento<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
        NodeList listadenodos <span style="color: #339933;">=</span> documento.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;obrero&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> listadenodos.<span style="color: #006633;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	Node nodo <span style="color: #339933;">=</span> listadenodos.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        	Obrero obrero <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Obrero<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nodo.<span style="color: #006633;">getNodeType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> Node.<span style="color: #006633;">ELEMENT_NODE</span><span style="color: #009900;">&#41;</span>
        	<span style="color: #009900;">&#123;</span>
        		<span style="color: #003399;">Element</span> elemento <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span><span style="color: #009900;">&#41;</span> nodo<span style="color: #339933;">;</span>
&nbsp;
        		obrero.<span style="color: #006633;">setNombre</span><span style="color: #009900;">&#40;</span>elemento.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        		obrero.<span style="color: #006633;">setCargo</span><span style="color: #009900;">&#40;</span>getValor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cargo&quot;</span>,elemento<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        		obrero.<span style="color: #006633;">setEdad</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>getValor<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;edad&quot;</span>,elemento<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        	<span style="color: #009900;">&#125;</span>
&nbsp;
        	listadoObreros.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>obrero<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #003399;">String</span> getValor <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> cadenatag, <span style="color: #003399;">Element</span> elemento<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	NodeList listado <span style="color: #339933;">=</span> elemento.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span>cadenatag<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	Node nodo <span style="color: #339933;">=</span> listado.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #000000; font-weight: bold;">return</span> nodo.<span style="color: #006633;">getNodeValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> ArrayList<span style="color: #339933;">&lt;</span>Obrero<span style="color: #339933;">&gt;</span> getListado<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000000; font-weight: bold;">return</span> listadoObreros<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fin del plugin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Clase obrero</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">vo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Obrero <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> edad<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> cargo<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getNombre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setNombre<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> nombre<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">nombre</span> <span style="color: #339933;">=</span> nombre<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getEdad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> edad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setEdad<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> edad<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">edad</span> <span style="color: #339933;">=</span> edad<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getCargo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> cargo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setCargo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> cargo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">cargo</span> <span style="color: #339933;">=</span> cargo<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Configuración del action en struts-config.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>action
&nbsp;
     path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/crearplugin&quot;</span>
     type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;acciones.AccionRecogerObreros&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
     <span style="color: #339933;">&lt;</span>forward  name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;satisfactorio&quot;</span> path<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/pages/listadoobreros.jsp&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #339933;">&lt;/</span>action<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Resultado final</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/listadoxml.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/listadoxml.png" alt="" title="listadoxml" width="580" height="300" class="alignnone size-full wp-image-1568" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/05/23/creacion-de-un-plugin-con-struts-xml-dom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Desarrollo web comodines struts</title>
		<link>http://www.railsymas.com/2010/05/14/desarrollo-web-comodines-struts/</link>
		<comments>http://www.railsymas.com/2010/05/14/desarrollo-web-comodines-struts/#comments</comments>
		<pubDate>Fri, 14 May 2010 21:14:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1516</guid>
		<description><![CDATA[Seguimos con el tutorial de struts Página jsp con varios ejemplos de utilización de comodines (wildcard) Creamos un fichero de configuración struts específico para el ejemplo y lo integramos en el fichero descriptor de despliegue en struts-configWildcard.xml 1 2 3 4 5 6 7 8 9 10 &#60;!-- Standard Action Servlet Configuration --&#62; &#60;servlet&#62; &#60;servlet-name&#62;action&#60;/servlet-name&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/wild1.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/wild1.png" alt="" title="wild1" width="282" height="44" class="alignnone size-full wp-image-1529" /></a></p>
<p><span id="more-1516"></span></p>
<p>Seguimos con el tutorial de struts</p>
<p>Página jsp con varios ejemplos de utilización de comodines (wildcard)</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/wil2.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/wil2.png" alt="" title="wil2" width="580" height="193" class="alignnone size-full wp-image-1530" /></a></p>
<p>Creamos un fichero de configuración struts específico para el ejemplo y lo integramos en el fichero descriptor de despliegue en struts-configWildcard.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #339933;">&lt;!--</span> Standard <span style="color: #003399;">Action</span> Servlet Configuration <span style="color: #339933;">--&gt;</span>
  <span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>action<span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>servlet<span style="color: #339933;">-</span>class<span style="color: #339933;">&gt;</span>org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">struts</span>.<span style="color: #006633;">action</span>.<span style="color: #006633;">ActionServlet</span><span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">-</span>class<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>init<span style="color: #339933;">-</span>param<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>param<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>config<span style="color: #339933;">&lt;/</span>param<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>param<span style="color: #339933;">-</span>value<span style="color: #339933;">&gt;/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>struts<span style="color: #339933;">-</span>config.<span style="color: #006633;">xml</span> , <span style="color: #339933;">/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>struts<span style="color: #339933;">-</span>config2.<span style="color: #006633;">xml</span> , <span style="color: #339933;">/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>struts<span style="color: #339933;">-</span>configWildcard.<span style="color: #006633;">xml</span> <span style="color: #339933;">&lt;/</span>param<span style="color: #339933;">-</span>value<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>init<span style="color: #339933;">-</span>param<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>load<span style="color: #339933;">-</span>on<span style="color: #339933;">-</span>startup<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>load<span style="color: #339933;">-</span>on<span style="color: #339933;">-</span>startup<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>servlet<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Configuración del archivo struts-configWildcard.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">struts-config&gt;
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- se puede aplicar a los  --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action-mappings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/enlaces&quot;</span> <span style="color: #000066;">forward</span>=<span style="color: #ff0000;">&quot;/pages/enlaces.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/Primero*&quot;</span> <span style="color: #000066;">forward</span>=<span style="color: #ff0000;">&quot;/pages/Wildcard/Paginap1.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/*segundo&quot;</span> <span style="color: #000066;">forward</span>=<span style="color: #ff0000;">&quot;/pages/Wildcard/{1}.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action-mappings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/struts-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>código de enlaces.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-html&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;html&quot;</span>  <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-bean&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bean&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;wildcard.enlace.titulo&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>base<span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../css/estilo.css&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
 	  <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span> Enlaces <span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>	
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenido&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>link action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;PrimeroPaginap1&quot;</span><span style="color: #339933;">&gt;</span> primero p<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>gina p1<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>link<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>link action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Paginap1segundo&quot;</span><span style="color: #339933;">&gt;</span> p<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>gina p1 segundo <span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>link<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>link action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Paginap2segundo&quot;</span><span style="color: #339933;">&gt;</span> primera p<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>gina p2 <span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>link<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span> www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span> <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Las páginas jsp son simples, no tienen ningun código especial</p>
<p>página 1 jsp</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/p1.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/p1.png" alt="" title="p1" width="580" height="120" class="alignnone size-full wp-image-1542" /></a></p>
<p>página 2 jsp</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/p21.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/p21.png" alt="" title="p2" width="580" height="120" class="alignnone size-full wp-image-1544" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/05/14/desarrollo-web-comodines-struts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Desarrollo web Múltiples archivos de configuración struts</title>
		<link>http://www.railsymas.com/2010/05/05/desarrollo-web-multiples-archivos-de-configuracion-struts/</link>
		<comments>http://www.railsymas.com/2010/05/05/desarrollo-web-multiples-archivos-de-configuracion-struts/#comments</comments>
		<pubDate>Wed, 05 May 2010 18:31:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1490</guid>
		<description><![CDATA[En este post veremos como crear diferentes archivos de configuración para el framework struts. Estamos con la versión 1.3.10 de struts y se llevan mostrados diferentes ejemplos sobre este framework. siempre a la hora de activar un componente de struts teníamos que ir al archivo de configuración, llega el momento en que este archivo de [...]]]></description>
			<content:encoded><![CDATA[<p>En este post veremos como crear diferentes archivos de configuración para el framework struts.</p>
<p><span id="more-1490"></span></p>
<p>Estamos con la versión 1.3.10 de struts y se llevan mostrados diferentes ejemplos sobre este framework. siempre a la hora de activar un componente de struts teníamos que ir al archivo de configuración, llega el momento en que este archivo de configuración esta sobrecargado de líneas de código.</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/ficherosconfiguración.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/ficherosconfiguración.png" alt="" title="ficherosconfiguración" width="317" height="118" class="alignnone size-full wp-image-1494" /></a> </p>
<p>En este ejemplo intervienen los dos archivos de configuración, declaración de una acción en el archivo de configuración de struts-config.xml  denominada  &#8220;multiconfiguración&#8221; y se produce el reenvio a la página enlaceprivado.jsp</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/multiconfiguracion&quot;</span>  </span>
<span style="color: #009900;">         <span style="color: #000066;">forward</span>=<span style="color: #ff0000;">&quot;/pages/enlaceprivado.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>Código de la página enlaceprivado</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>@ page language<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;java&quot;</span> contentType<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span>  pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-html&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;html&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://struts.apache.org/tags-bean&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;bean&quot;</span> <span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>base<span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;&lt;</span>bean<span style="color: #339933;">:</span>message key<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enlaceprivado.titulo&quot;</span><span style="color: #339933;">/&gt;</span> <span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../css/estilo.css&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenedor&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contenido&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campo&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>html<span style="color: #339933;">:</span>link action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/config2&quot;</span><span style="color: #339933;">&gt;</span> Zona privada <span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>link<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;pie&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>www.<span style="color: #006633;">railsymas</span>.<span style="color: #006633;">com</span> <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span> 
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">:</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>En esa página jsp existe un enlace que activa la acción config2 que aparece en el fichero de configuración struts-config2.xml</p>
<p>Enlace imagen<br />
<a href="http://www.railsymas.com/wp-content/uploads/2010/05/enlace1.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/enlace1.png" alt="" title="enlace" width="580" height="91" class="alignnone size-full wp-image-1500" /></a></p>
<p>Se declara en struts-config2.xml  un bean dinámico llamado formularioprivado  con dos campos de tipo string, y una acción privado, que va ser tratada desde struts-config2.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;formularioprivado&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.apache.struts.validator.DynaValidatorForm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>  
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;usuario&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clave&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;java.lang.String&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action-mappings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span>      </span>
<span style="color: #009900;">     path =<span style="color: #ff0000;">&quot;/config2&quot;</span></span>
<span style="color: #009900;">     forward =<span style="color: #ff0000;">&quot;/pages/privado.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> </span>
<span style="color: #009900;">      <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/privado&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;acciones.Privado&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;formularioprivado&quot;</span>      </span>
<span style="color: #009900;">      <span style="color: #000066;">input</span>=<span style="color: #ff0000;">&quot;/pages/privado.jsp&quot;</span>     </span>
<span style="color: #009900;">      <span style="color: #000066;">validate</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000000; font-weight: bold;">&gt;</span></span>            
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;satisfactorio&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/pages/satisfactorio.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forward</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;error&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/pages/cancelada2.jsp&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>      
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>visualización de la página privado donde se muestra un formulario de usuario, </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/formularioconf21.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/formularioconf21.png" alt="" title="formularioconf2" width="580" height="300" class="alignnone size-full wp-image-1510" /></a></p>
<p>En el fichero web.xml del proyecto</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"> <span style="color: #808080; font-style: italic;">&lt;!-- Standard Action Servlet Configuration --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>action<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.struts.action.ActionServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>config<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/struts-config.xml , /WEB-INF/struts-config2.xml <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/05/05/desarrollo-web-multiples-archivos-de-configuracion-struts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

