<?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; java j2ee</title>
	<atom:link href="http://www.railsymas.com/category/java-j2ee/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.railsymas.com</link>
	<description>Nuevas Tecnologías</description>
	<lastBuildDate>Fri, 30 Jul 2010 22:45:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Autentificación j2ee Formularios</title>
		<link>http://www.railsymas.com/2010/06/14/autentificacion-j2ee-formularios/</link>
		<comments>http://www.railsymas.com/2010/06/14/autentificacion-j2ee-formularios/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 17:36:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1606</guid>
		<description><![CDATA[Habíamos visto un ejemplo de autentificación básica con tomcat en un ejemplo anterior En este ejemplo vamos a utilizar unos formularios para validar al usuario y así personalizar un poco más el proceso código de la página index.jsp 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [...]]]></description>
			<content:encoded><![CDATA[<p> Habíamos visto un ejemplo de autentificación básica con tomcat en un ejemplo anterior</p>
<p> <span id="more-1606"></span></p>
<p>En este ejemplo vamos a utilizar unos formularios para validar al usuario y así personalizar un poco más el proceso</p>
<p>código de la página index.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
</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>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;</span>Inicio<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>
&nbsp;
 El usuario se ha validado correctamente
&nbsp;
&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>
 <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>imagen de la página index</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/authindex.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/authindex.png" alt="" title="authindex" width="523" height="85" class="alignnone size-full wp-image-1617" /></a></p>
<p>Código de la página de login.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
37
</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>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;</span>formulario de login<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>
&nbsp;
 <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;</span>Formulario Login<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</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;j_security_check&quot;</span><span style="color: #339933;">&gt;</span>
 <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;campos&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>nombre de usuario<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;j_username&quot;</span><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: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;campos&quot;</span><span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>clave de usuario<span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
 <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;j_password&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>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;enviar&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;boton&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
&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>
 <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<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>imagen el usuario metiendo sus datos</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/authlogin.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/authlogin.png" alt="" title="authlogin" width="520" height="243" class="alignnone size-full wp-image-1610" /></a></p>
<p>código de la página de error</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
</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>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;</span>Error<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>
&nbsp;
 <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: #003399;">Error</span> usuario no v<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>lido volver a  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">'&lt;%= response.encodeURL(&quot;login.jsp&quot;) %&gt;'</span><span style="color: #339933;">&gt;</span>login<span style="color: #339933;">&lt;/</span>a<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>
&nbsp;
<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>Imagen en caso de introducir mal los datos del usuario</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/06/errorauthenlo.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/06/errorauthenlo.png" alt="" title="errorauthenlo" width="518" height="79" class="alignnone size-full wp-image-1608" /></a></p>
<p>configuración del archivo web.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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>		
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Zona privada<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>usuariovalido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-constraint<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;login-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FORM<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;realm-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>zona restringida<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/realm-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-login-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-login-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/login.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-login-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form-error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/error.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-error-page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form-login-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/login-config<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;security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Usuario Valido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>usuariovalido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role<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/06/14/autentificacion-j2ee-formularios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autentificación básica j2ee</title>
		<link>http://www.railsymas.com/2010/05/27/autentificacion-basica-j2ee/</link>
		<comments>http://www.railsymas.com/2010/05/27/autentificacion-basica-j2ee/#comments</comments>
		<pubDate>Thu, 27 May 2010 15:04:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1572</guid>
		<description><![CDATA[En este primer post sobre roles y autenficación en j2ee veremos algunos de los mecanismos utilizados por la tecnología java enterprice para solventar estas cuestiones Introducción teórica La tecnología de servlets tiene diversos métodos para implementar los procedimientos de autentificación - básico http, Compendio http, basado en formularios, cliente https En este ejemplo se muesta [...]]]></description>
			<content:encoded><![CDATA[<p> En este primer post sobre roles y autenficación en j2ee veremos algunos de los mecanismos utilizados por la tecnología java enterprice para solventar estas cuestiones</p>
<p><span id="more-1572"></span></p>
<p>Introducción teórica</p>
<p>La tecnología de servlets tiene diversos métodos para implementar los procedimientos de autentificación</p>
<p>- básico http,  Compendio http, basado en formularios, cliente https</p>
<p>En este ejemplo se muesta la forma básica http, mediante el objeto httpServletRequest, que devuelve la identificación del usuario remoto y por medio del objeto getAutType se devuelve el mecanismo de autenticación</p>
<p>Hay que añadir el usuario nuevo al archivo tomcat-users.xml que se encuentra en el directorio de apache tomcat\conf y allí editar el archivo. Una vez hecho eso se reincia tomcat para cargar los datos. </p>
<p>Código del servlet ZonaPrivada encargado de recuperar datos de la petición</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
</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;">conexion</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</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;">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;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Servlet implementation class for Servlet: ZonaPrivada
 *
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ZonaPrivada <span style="color: #000000; font-weight: bold;">extends</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span> <span style="color: #000000; font-weight: bold;">implements</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> ZonaPrivada<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;">super</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: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		 response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		 <span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		 <span style="color: #003399;">String</span> tipo <span style="color: #339933;">=</span> request.<span style="color: #006633;">getAuthType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		 salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El tipo de autenticacion es: &quot;</span><span style="color: #339933;">+</span>tipo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		 salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El usuario es &quot;</span><span style="color: #339933;">+</span>request.<span style="color: #006633;">getUserPrincipal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</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;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>  	
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Dentro del archivo web,xml se asigna la ruta /zonaprivada como ruta protegida,  el nombre del rol como (usuariovalido) y un nombre de usuario (usuario) y una contraseña (válido).</p>
<p>configuración del servlet ZonaPrivada en el fichero web.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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><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;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		ZonaPrivada<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-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-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ZonaPrivada<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>
		conexion.ZonaPrivada<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;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<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>ZonaPrivada<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;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/zonaprivada<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Configuración de las restricciones</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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Zona privada<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/zonaprivada<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>usuariovalido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;login-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>BASIC<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;realm-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>zona restringida<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/realm-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/login-config<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;security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Usario Valido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>usuariovalido<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>archivo tomcat-users.xml añadimos para el nuevo rol</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: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'utf-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tomcat-users<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">rolename</span>=<span style="color: #ff0000;">&quot;usuariovalido&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;usuario&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;valido&quot;</span> <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;usuariovalido&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;/tomcat-users<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>formulario de identificación gestionado por tomcat</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/Identificación-requerida.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/Identificación-requerida.png" alt="" title="Identificación requerida" width="558" height="202" class="alignnone size-full wp-image-1580" /></a></p>
<p>imagen resultado</p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2010/05/identificacionresultado.png"><img src="http://www.railsymas.com/wp-content/uploads/2010/05/identificacionresultado.png" alt="" title="identificacionresultado" width="258" height="140" class="alignnone size-full wp-image-1582" /></a></p>
<p>enlace para colocar adecuadamente las restricciones en el fichero web.xml</p>
<p><a href="http://www.eclipse.org/webtools/jst/components/j2ee/scenarios/web_validation_testplan.html"> enlace</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/05/27/autentificacion-basica-j2ee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Desarrollo web parámetros init j2ee</title>
		<link>http://www.railsymas.com/2010/04/13/desarrollo-web-parametros-init-j2ee/</link>
		<comments>http://www.railsymas.com/2010/04/13/desarrollo-web-parametros-init-j2ee/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 21:41:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=1426</guid>
		<description><![CDATA[Los servlets de j2ee además de recibir peticiones de tipo get y post nos permiten recoger valores y parámetros prefijados en el archivo de despliegue de la aplicación. Tomamos como punto de partida, la aplicación realizada sobre jdbc Enlace: jdbc elipse Las modificaciones que se van a realizar en el método init del servlet base [...]]]></description>
			<content:encoded><![CDATA[<p>
  Los servlets de j2ee además de  recibir peticiones de tipo get y post nos permiten recoger valores y parámetros prefijados en el archivo de despliegue de la aplicación.<br />
  <span id="more-1426"></span> </p>
<p>  Tomamos como punto de partida, la aplicación realizada sobre jdbc Enlace: <a href="http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/">jdbc elipse</a></p>
<p>  Las modificaciones que se van a realizar en el método init del servlet base de datos le permiten cargar los valores del driver y el nombre de la base de datos declarados en el fichero web.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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><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;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		basedatos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-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-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>basedatos<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>
		conexion.basedatos<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>nombreBasedatos<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>jdbc:mysql://localhost:3306/libros_jdbc<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;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>driver<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>com.mysql.jdbc.Driver<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;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Solamente se modifica el método init para recuperar los valores de los parámetros</p>
<p>mediante las etiquetas <init-param> introducimos los pares
<param-name>, para el nombre del parámetro y
<param-value> para el valor del parámetro.</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"> 	<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><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">init</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>
			<span style="color: #666666; font-style: italic;">//String controlador = &quot;com.mysql.jdbc.Driver&quot;;</span>
&nbsp;
&nbsp;
			<span style="color: #003399;">String</span> controlador <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getInitParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;driver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span>controlador<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
			<span style="color: #666666; font-style: italic;">//conectamos con la base de datos</span>
			<span style="color: #666666; font-style: italic;">//conexion = DriverManager.getConnection(&quot;jdbc:mysql://localhost:3306/libros_jdbc&quot;,&quot;root&quot;,&quot;root&quot;);</span>
&nbsp;
			<span style="color: #003399;">String</span> baseDatosUrl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getInitParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombreBasedatos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			conexion <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span>baseDatosUrl,<span style="color: #0000ff;">&quot;root&quot;</span>,<span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//creamos una sentencia sql</span>
			sentenciaSql <span style="color: #339933;">=</span> conexion.<span style="color: #006633;">createStatement</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;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">ClassNotFoundException</span> 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 pudo cargar el controlador&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;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">SQLException</span> 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;Excepcion sql&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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InstantiationException</span> 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;objeto no creado&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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">IllegalAccessException</span> 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;Acceso ilegal&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>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Mediante el método getInitParameter recuperamos los valores de los parámetros del servlet. Estos valores pueden ser utilizados únicamente por el servlet basededatos no por otros servlet. Para ser utilizados por otros servlet se necesita declarar parámetros de contexto, se verá en otro ejemplo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2010/04/13/desarrollo-web-parametros-init-j2ee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datasource j2ee proyecto web eclipse</title>
		<link>http://www.railsymas.com/2009/12/03/datasource-j2ee-proyecto-web-eclipse/</link>
		<comments>http://www.railsymas.com/2009/12/03/datasource-j2ee-proyecto-web-eclipse/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 16:08:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=954</guid>
		<description><![CDATA[Habíamos visto en anteriores post como acceder a una base de datos con jdbc y con ibatis en esta ocasición veremos la creación y conexión del mismo ejemplo mediante un datasource Se mostraran por pantalla los datos almacenados en la base de datos libros_jdbc para su tabla libros Enlace al ejemplo de j2ee jdbc j2ee [...]]]></description>
			<content:encoded><![CDATA[<p>Habíamos visto en anteriores post como acceder a una base de datos con jdbc y con ibatis en esta ocasición veremos la creación y conexión del mismo ejemplo mediante un datasource</p>
<p><span id="more-954"></span></p>
<p>Se mostraran por pantalla los datos almacenados en la base de datos libros_jdbc para su tabla libros</p>
<p>Enlace al ejemplo de j2ee jdbc <a href="http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/">j2ee jdbc</a></p>
<p>Configuración del fichero web.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="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;web-app</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;WebApp_ID&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.4&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	conexionjdbc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>DB Connection<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdbc/Conexiondatasource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.sql.DataSource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Container<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Imagen del fichero de context.xml</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/12/contexto.png" alt="contexto" title="contexto" width="225" height="153" class="alignnone size-full wp-image-973" /></p>
<p>Fichero de configuración del contexto  context.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
</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;Context</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/Conexiondatasource&quot;</span> <span style="color: #000066;">docBase</span>=<span style="color: #ff0000;">&quot;Conexiondatasource&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">debug</span>=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">crossContext</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- maxActive: Maximum number of dB connections in pool. Make sure you</span>
<span style="color: #808080; font-style: italic;">         configure your mysqld max_connections large enough to handle</span>
<span style="color: #808080; font-style: italic;">         all of your db connections. Set to -1 for no limit.</span>
<span style="color: #808080; font-style: italic;">         --&gt;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- maxIdle: Maximum number of idle dB connections to retain in pool.</span>
<span style="color: #808080; font-style: italic;">         Set to -1 for no limit.  See also the DBCP documentation on this</span>
<span style="color: #808080; font-style: italic;">         and the minEvictableIdleTimeMillis configuration parameter.</span>
<span style="color: #808080; font-style: italic;">         --&gt;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- maxWait: Maximum time to wait for a dB connection to become available</span>
<span style="color: #808080; font-style: italic;">         in ms, in this example 10 seconds. An Exception is thrown if</span>
<span style="color: #808080; font-style: italic;">         this timeout is exceeded.  Set to -1 to wait indefinitely.</span>
<span style="color: #808080; font-style: italic;">         --&gt;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- username and password: MySQL dB username and password for dB connections  --&gt;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- driverClassName: Class name for the old mm.mysql JDBC driver is</span>
<span style="color: #808080; font-style: italic;">         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.</span>
<span style="color: #808080; font-style: italic;">         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.</span>
<span style="color: #808080; font-style: italic;">         --&gt;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- url: The JDBC connection url for connecting to your MySQL dB.</span>
<span style="color: #808080; font-style: italic;">         --&gt;</span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/Conexiondatasource&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost:3306/libros_jdbc&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;/Context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Imagen resultado de la ejecución</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/12/conexiondatasource.png" alt="conexiondatasource" title="conexiondatasource" width="520" height="410" class="alignnone size-full wp-image-968" /></p>
<p>Código de la clase Conexionpool.java</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
</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;">conexion</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</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;">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;">java.io.PrintWriter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.naming.InitialContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Statement</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.naming.NamingException</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Servlet implementation class for Servlet: Conexionpool
 *
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Conexionpool <span style="color: #000000; font-weight: bold;">extends</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span> <span style="color: #000000; font-weight: bold;">implements</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Connection</span> conexion <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;">Statement</span> sentenciaSql <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;">ResultSet</span>  resultado <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> Conexionpool<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;">super</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: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #009900;">&#123;</span> 
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">InitialContext</span> ctx <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InitialContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		DataSource ds <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DataSource<span style="color: #009900;">&#41;</span> ctx.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java:comp/env/jdbc/Conexiondatasource&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> ds <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</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;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Data source no encontrado!&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;">this</span>.<span style="color: #006633;">conexion</span> <span style="color: #339933;">=</span> ds.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//creamos una sentencia sql</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sentenciaSql</span> <span style="color: #339933;">=</span> conexion.<span style="color: #006633;">createStatement</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><span style="color: #003399;">NamingException</span> 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>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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">SQLException</span> 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>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;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
        response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</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>
			<span style="color: #666666; font-style: italic;">//ejecutamos la sentencia de selección de los campos menos el id</span>
			resultado <span style="color: #339933;">=</span> sentenciaSql.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; SELECT titulo, autor, tematica  FROM libros;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//preparamos la salida para una nueva página</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;&lt;title&gt;Mostramos los datos&lt;/title&gt;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Libros datasource &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;table id='tabla'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;th&gt;titulo&lt;/th&gt;&lt;th&gt;autor&lt;/th&gt;&lt;th&gt;tematica&lt;/th&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> resultado.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>   
&nbsp;
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='impar'&gt;&quot;</span><span style="color: #339933;">+</span>resultado.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='par'&gt;&quot;</span><span style="color: #339933;">+</span>resultado.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='impar'&gt;&quot;</span><span style="color: #339933;">+</span>resultado.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			   salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span> 	<span style="color: #003399;">SQLException</span> e <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Excepcion Sql : &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;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>  	
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
	<span style="color: #009900;">&#125;</span>   	  	    
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/12/03/datasource-j2ee-proyecto-web-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diferencias entre el  Modelo 1 y Modelo 2 jsp</title>
		<link>http://www.railsymas.com/2009/11/09/diferencias-entre-el-modelo-1-y-modelo-2-jsp/</link>
		<comments>http://www.railsymas.com/2009/11/09/diferencias-entre-el-modelo-1-y-modelo-2-jsp/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 01:03:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=900</guid>
		<description><![CDATA[Modelo1.jsp El modelo uno de páginas jsp es un tipo de desarrollo donde el nivel de presentación se utiliza archivos html o los archivos jsp. Los archivos jsp pueden llevar javabeans para recuperar datos de las bases de datos. Los archivos jsp son los responsables de la lógica de negocios, reciben peticiones y direccionan a [...]]]></description>
			<content:encoded><![CDATA[<p>Modelo1.jsp</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/11/modelo1.png" alt="modelo1" title="modelo1" width="213" height="75" class="alignnone size-full wp-image-908" /></p>
<p>El modelo uno de páginas jsp es un tipo de desarrollo donde el nivel de presentación se utiliza archivos html o los archivos jsp. Los archivos jsp pueden llevar javabeans para recuperar datos de las bases de datos.</p>
<p>Los archivos jsp son los responsables de la lógica de negocios, reciben peticiones y direccionan a la jsp correcta, es un diseño centrado en la página toda la lógica se desarrolla en las propias páginas</p>
<p>Como resumen decir que en este ejemplo para el modelo 1 la página jsp recibe la información recibida de la página html y la jsp se encarga de procesar la petición verificando que el usuario admin ha metido la clave admin para luego en la misma página mostrar la información correspondiente según la entrada de datos del formulario</p>
<p>con recuperamos la informacion del campo usuario</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> usuario <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;usuario&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span id="more-900"></span></p>
<p>Código de la página formulario1.html</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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><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;</span>Modelo1 jsp<span style="color: #339933;">&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>h2<span style="color: #339933;">&gt;</span> Formulario de usuario <span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>form  action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;validacionlogin1.jsp&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span> Nombre<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span>  name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;usuario&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span> Contraseña<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span>  name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span> 
&nbsp;
  <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&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>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;reset&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cancelar&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<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>Código de la página validacionlogin1.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
</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>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;</span>Medelo <span style="color: #cc66cc;">1</span> jsp<span style="color: #339933;">&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>  
     <span style="color: #003399;">String</span> usuario <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;usuario&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003399;">String</span> contrasenia <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</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> usuario.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> contrasenia.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
    	 out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Bienvenido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	 out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;usuario&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    	 out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;hr/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	 out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &lt;a href='tiempo.jsp'&gt; El Tiempo &lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	 out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &lt;a href='deportes.jsp'&gt; Deportes  &lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	 out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;a href='noticias.jsp'&gt; Noticias &lt;/a&gt; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000000; font-weight: bold;">else</span>
     <span style="color: #009900;">&#123;</span>
    	out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; Login invalidado. &lt;a href='formulario.jsp'&gt; Intentalo otra vez &lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
   <span style="color: #339933;">%&gt;</span>
&nbsp;
<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>Modelo 2 jsp </p>
<p>Para el modelo 2 tenemos una serie de páginas jsp que se encargan de mostrar solamante información, mientras que tenemos una jsp que actua como controlador, recibe las peticiones las procesa y despacha a otras jsp que muestran la vista de los resultados.</p>
<p>La página jsp que funciona como controlador es validacionlogin.jsp, se realiza un forward, un reenvío a otra página jsp pasando el valor recogido del formulario a la página jsp menú de la vista.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;</span>jsp<span style="color: #339933;">:</span>forward page<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu.jsp&quot;</span> <span style="color: #339933;">&gt;</span>
    	   <span style="color: #339933;">&lt;</span>jsp<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nombre&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;%=usuario%&gt;&quot;</span> <span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;/</span>jsp<span style="color: #339933;">:</span>forward<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Imagen correspondiente al proyecto</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/11/modelo2.png" alt="modelo2" title="modelo2" width="257" height="285" class="alignnone size-full wp-image-902" /></p>
<p>Tenemos cuatro  páginas</p>
<p>Página formulario.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
</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>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;</span>Formulario<span style="color: #339933;">&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>
&nbsp;
  <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span> Formulario de usuario <span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>form  action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;validacionlogin.jsp&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span> Nombre<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span>  name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;usuario&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span> Contraseña<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;/</span>label<span style="color: #339933;">&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span>  name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">/&gt;</span> 
&nbsp;
  <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&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>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;reset&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;cancelar&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
  <span style="color: #339933;">&lt;/</span>form<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>Página validacionlogin.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
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<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>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;</span>validacion de login<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
&nbsp;
<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>
&nbsp;
    <span style="color: #339933;">&lt;%</span>  
&nbsp;
     <span style="color: #003399;">String</span> usuario <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;usuario&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003399;">String</span> contrasenia <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</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> usuario.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> contrasenia.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
&nbsp;
     <span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #339933;">%&gt;</span>
&nbsp;
     <span style="color: #339933;">&lt;</span>jsp<span style="color: #339933;">:</span>forward page<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;menu.jsp&quot;</span> <span style="color: #339933;">&gt;</span>
    	   <span style="color: #339933;">&lt;</span>jsp<span style="color: #339933;">:</span>param name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nombre&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;%=usuario%&gt;&quot;</span> <span style="color: #339933;">/&gt;</span>
     <span style="color: #339933;">&lt;/</span>jsp<span style="color: #339933;">:</span>forward<span style="color: #339933;">&gt;</span>
&nbsp;
     <span style="color: #339933;">&lt;%</span>
&nbsp;
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000000; font-weight: bold;">else</span>
     <span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #339933;">%&gt;</span>
&nbsp;
     <span style="color: #339933;">&lt;</span>jsp<span style="color: #339933;">:</span>forward page<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error.jsp&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;%</span> 
&nbsp;
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #339933;">%&gt;</span>  	 
&nbsp;
<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>Página menu.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
</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>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;</span>Menu<span style="color: #339933;">&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>
&nbsp;
  Bienvenido <span style="color: #339933;">&lt;%</span> out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getParameter</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> <span style="color: #339933;">%&gt;</span>
  <span style="color: #339933;">&lt;</span>hr<span style="color: #339933;">/&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tiempo.jsp&quot;</span><span style="color: #339933;">&gt;</span> El Tiempo <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;deportes.jsp&quot;</span><span style="color: #339933;">&gt;</span> Deportes  <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;noticias.jsp&quot;</span><span style="color: #339933;">&gt;</span> Noticias <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
&nbsp;
<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>Página de error.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
</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>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;</span>P<span style="color: #339933;">&amp;</span>aacute<span style="color: #339933;">;</span>gina de Error<span style="color: #339933;">&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>
&nbsp;
  Login invalidado. <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;formulario.jsp&quot;</span><span style="color: #339933;">&gt;</span> Intentalo otra vez <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
&nbsp;
<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>Ejecución es la misma en ambos casos</p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/11/09/diferencias-entre-el-modelo-1-y-modelo-2-jsp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Patrón de desarrollo singleton java</title>
		<link>http://www.railsymas.com/2009/10/10/patron-de-desarrollo-singleton-java/</link>
		<comments>http://www.railsymas.com/2009/10/10/patron-de-desarrollo-singleton-java/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 17:38:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=750</guid>
		<description><![CDATA[El patrón de diseño singleton (instancia única) está diseñado para restringir la creación de objetos pertenecientes a una clase o el valor de un tipo a un único objeto. El patrón singleton se implementa creando en nuestra clase un método que crea una instancia del objeto sólo si todavía no existe alguna. Para que asegurarnos [...]]]></description>
			<content:encoded><![CDATA[<p>El patrón de diseño singleton (instancia única) está diseñado para restringir la creación de objetos pertenecientes a una clase o el valor de un tipo a un único objeto.</p>
<p>El patrón singleton se implementa creando en nuestra clase un método que crea una instancia del objeto sólo si todavía no existe alguna. Para que asegurarnos que la clase solamente se puede hacer una vez, ponemos el constructor privado o protected, y creamos el new desde otro método verificando sin la instancia fué creada  </p>
<p><span id="more-750"></span></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
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Singleton <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// atributo de la clase que determina que una</span>
	<span style="color: #666666; font-style: italic;">// que solamente se va a crear uno </span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Singleton unico <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//constructor privado de la clase para </span>
	<span style="color: #666666; font-style: italic;">//que solo un método de la clase pueda crearlo</span>
	<span style="color: #000000; font-weight: bold;">private</span> Singleton <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Singleton obtenerInstancia<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>   
		<span style="color: #666666; font-style: italic;">//para asegurarnos de que es el único</span>
		   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>unico <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
		   <span style="color: #009900;">&#123;</span>
			   unico <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Singleton<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;">return</span>  unico<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> instancias<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;">if</span> <span style="color: #009900;">&#40;</span> unico <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</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;no se pueden crear mas instancias&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">// método del singleton </span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> mensaje<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> <span style="color: #0000ff;">&quot;Creada la instancia singleton&quot;</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> <span style="color: #000066; font-weight: bold;">void</span> main <span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	   <span style="color: #666666; font-style: italic;">//para crear un objeto de la clase </span>
	   Singleton sin <span style="color: #339933;">=</span> Singleton.<span style="color: #006633;">obtenerInstancia</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	   <span style="color: #003399;">String</span> mensaje <span style="color: #339933;">=</span> sin.<span style="color: #006633;">mensaje</span><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;">//sacamos por pantalla el mensaje de </span>
	   <span style="color: #666666; font-style: italic;">//Creada la instancia singleton</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>mensaje<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	   <span style="color: #666666; font-style: italic;">//intentamos crear una nueva instancia</span>
	   sin<span style="color: #339933;">=</span> Singleton.<span style="color: #006633;">obtenerInstancia</span><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;">//preguntamos si no hay mas instancias</span>
	   sin.<span style="color: #006633;">instancias</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></pre></td></tr></table></div>

<p>Salida por pantalla </p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/singleton.png" alt="singleton" title="singleton" width="557" height="132" class="alignnone size-full wp-image-751" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/10/10/patron-de-desarrollo-singleton-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sesiones j2ee proyecto web eclipse</title>
		<link>http://www.railsymas.com/2009/10/07/sesiones-j2ee-proyecto-web-eclipse/</link>
		<comments>http://www.railsymas.com/2009/10/07/sesiones-j2ee-proyecto-web-eclipse/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 21:24:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=725</guid>
		<description><![CDATA[Tutorial sesiones Explicación del ejemplo, un servlet que muestra por get una página html con un formulario con dos campos, nombre y apellidos. El mismo servlet tiene un método post que crea una sesión nueva introduciendo los datos pasados por el formulario y mostrando un html con los datos pasados guardados en sesión y un [...]]]></description>
			<content:encoded><![CDATA[<p>Tutorial sesiones</p>
<p>Explicación del ejemplo, un servlet que muestra por get una página html con un formulario con dos campos, nombre y apellidos.  El mismo servlet tiene un método post que crea una sesión nueva introduciendo los datos pasados por el formulario y mostrando un html con los datos pasados guardados en sesión y un enlace al formulario get del servlets, más un formulario para el método post cancelando la sesión creada.</p>
<p><span id="more-725"></span></p>
<p>Sesiones: Uso con Servlets</p>
<p> – Activar la sesion desde HttpServletRequest<br />
    sesion = request.getSession(true);</p>
<p> – Uso de atributos en una sesión: HttpSession<br />
    sesion.setAttribute(“identificacion”, new String(“11.15br”));<br />
    out.println( “Su identificacion es “ + session.getAttribute(“identificacion”));<br />
    sesion.removeAttribute(“identificacion”);</p>
<p> – Invalidar una sesión<br />
    sesion.invalidate();</p>
<p>– Mostrar el identificador de una sesión:<br />
    out.println(“identificacion de la sesión actual: “ + sesion.getIdentificacion());</p>
<p>Se ejecuta el servlet por el método get, imagen correspondiente</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/formulariosesion.png" alt="formulariosesion" title="formulariosesion" width="550" height="380" class="alignnone size-full wp-image-729" /></p>
<p>Se ha enviado los campos del formulario responde el método post con la siguiente página</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/formulariosesion2.png" alt="formulariosesion2" title="formulariosesion2" width="525" height="346" class="alignnone size-full wp-image-731" /></p>
<p>Si le damos al enlace del formulario metiendo otros valores, como la sesión es la misma, para el usuario aunque rellene el formulario, con otros datos. El resultado será el que se muestra en la siguiente imagen</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/formulariosesion31.png" alt="formulariosesion3" title="formulariosesion3" width="550" height="350" class="alignnone size-full wp-image-736" /></p>
<p>Si pulsamos sobre el botón cancelar, entonces la sesión es invalidada y al pusar sobre el enlace del formulario, podemos registrarnos ya sí, con otro nombre</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/10/formulariosesion4.png" alt="formulariosesion4" title="formulariosesion4" width="538" height="258" class="alignnone size-full wp-image-734" /></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
</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;">sesiones</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</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;">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.http.HttpSession</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Servlet implementation class for Servlet: Usuario
 *
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Usuario <span style="color: #000000; font-weight: bold;">extends</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span> <span style="color: #000000; font-weight: bold;">implements</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> HttpSession sesionUsuario<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> Usuario<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;">super</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: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><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;">//creamos la salida del html</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Formulario Sesiones &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='imagen'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;img src='imagenes/usuario.png' title='usuario'/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;form action='Usuario' method='post'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Nombre&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='nombre'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Apellidos&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='apellidos'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input class='boton' type='submit' value='enviar'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/form&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>  	
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//recuperamos los datos del formulario</span>
&nbsp;
		<span style="color: #003399;">String</span> nombre <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombre&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> apellidos <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;apellidos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> cancelada <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cancelar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//recuperamos el objeto de sesión asociado a la petición</span>
		sesionUsuario <span style="color: #339933;">=</span> request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
        <span style="color: #666666; font-style: italic;">//establecemos el tipo de respuesta </span>
		response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><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;">//creamos la salida del html</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Resultado Sesi&amp;oacute;n &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='imagen'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;img src='imagenes/usuario.png' title='carpeta'/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//si la sesion es nueva</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> sesionUsuario.<span style="color: #006633;">isNew</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>   
			<span style="color: #666666; font-style: italic;">//establecemos los atributos de sesión</span>
			sesionUsuario.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nombre&quot;</span>, nombre<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			sesionUsuario.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;apellidos&quot;</span>, apellidos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; Usuario nombre: &quot;</span><span style="color: #339933;">+</span>sesionUsuario.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; Usuario apellidos: &quot;</span><span style="color: #339933;">+</span>sesionUsuario.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;apellidos&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&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;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>cancelada <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>	
&nbsp;
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; Ya estas dentro del sistema &lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; Usuario nombre: &quot;</span><span style="color: #339933;">+</span>sesionUsuario.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&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>
				<span style="color: #666666; font-style: italic;">//cancelamos la sesión</span>
				sesionUsuario.<span style="color: #006633;">invalidate</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;
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;form action='Usuario' method='post'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Cancelar Session&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input class='boton' type='submit' name='cancelar' value='cancelar'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/form&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;a href='/conexionjdbc/Usuario'&gt;Formulario Sesi&amp;oacute;n&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>   	  	    
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/10/07/sesiones-j2ee-proyecto-web-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ibatis proyecto web eclipse</title>
		<link>http://www.railsymas.com/2009/09/30/ibatis-proyecto-web-eclipse/</link>
		<comments>http://www.railsymas.com/2009/09/30/ibatis-proyecto-web-eclipse/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 20:17:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=700</guid>
		<description><![CDATA[Tutorial de Ibatis Lo primero, como bien dice la wikipedia ibatis es un marco de trabajo desarrollado por apache que se ocupa de la capa de persistencia, situándose entre la capa de negocio y la base de datos. Ibatis esta disponible para java .net y ruby on rails. Ibatis cumple una función similar a la [...]]]></description>
			<content:encoded><![CDATA[<p>Tutorial de  Ibatis</p>
<p>Lo primero, como bien dice la wikipedia ibatis es un marco de trabajo desarrollado por apache que se ocupa de la capa de persistencia, situándose entre la capa de negocio y la base de datos. Ibatis esta disponible para java .net y ruby on rails. </p>
<p>Ibatis cumple una función similar a la de hibernate, algunos desarrolladores consideran a ibatis una alternativa por su sencillez y por no presentar un lenguaje específico para consultas. </p>
<p><span id="more-700"></span></p>
<p>En la página web del proyecto ibatis  enlace <a href="http://ibatis.apache.org/">proyecto  ibatis</a></p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/ibatisproject.png" alt="ibatisproject" title="ibatisproject" width="570" height="230" class="alignnone size-full wp-image-704" /></p>
<p>Recordar que este ejemplo esta realizado en linux ubuntu pero que es totalmente compatible con windows.</p>
<p>Descargar la versión 2.3.0 o la versión 2.3.4 con las que se ha probado el ejemplo, una vez descargado y desempaquetado  el proyecto dentro de la carpeta lib tenemos un fichero .jar con la versión correspondiente. Ese fichero debemos del importarlo el directorio lib de nuestro proyecto web dinámico de eclipse.</p>
<p>Partimos de la situación del ejemplo  jdbc eclipse, nos habíamos descargado mysql, y el jar driver para jdbc creando la base de datos libros_jdbc, con una tabla llamada libros. En ese ejemplo creabamos un servlet que por método get mostraba un formulario para enviar después los datos por método post, insertar los datos y mostrar un listado de lo almacenado en la tabla.</p>
<p>Enlace al ejemplo anterior <a href="http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/">Conexión a bases de datos j2ee jdbc eclipse</a></p>
<p>Clase Bean Libro.java</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: #000000; font-weight: bold;">package</span> <span style="color: #006699;">conexion</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> Libro <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id_libro<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> titulo_libro<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> autor_libro<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> tematica_libro<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId_libro<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> id_libro<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> setId_libro<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id_libro<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;">id_libro</span> <span style="color: #339933;">=</span> id_libro<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> getTitulo_libro<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> titulo_libro<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> setTitulo_libro<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> titulo_libro<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;">titulo_libro</span> <span style="color: #339933;">=</span> titulo_libro<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> getAutor_libro<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> autor_libro<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> setAutor_libro<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> autor_libro<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;">autor_libro</span> <span style="color: #339933;">=</span> autor_libro<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> getTematica_libro<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> tematica_libro<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> setTematica_libro<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> tematica_libro<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;">tematica_libro</span> <span style="color: #339933;">=</span> tematica_libro<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ficheros de configuración para ibatis son tres y los pondremos en un package ibatisMap</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/ficheroibatis.png" alt="ficheroibatis" title="ficheroibatis" width="264" height="198" class="alignnone size-full wp-image-719" /></p>
<p>El fichero basedatos.java es el servlet del anterior ejemplo jdbc el utilizado para ibatis es BaseDatosIbatis.java</p>
<p>En el propio proyecto de apache ibatis tienen tutoriales indicando la funcionalidad de cada uno de los ficheros necesarios para ibatis</p>
<p>Creamos un fichero xml para el mapeo del bean Libro &#8220;Libro.xml&#8221;, este fichero contiene el conjunto de consultas que van a ser utilizadas para el bean asociado a la tabla libros</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
</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 sqlMap</span>
<span style="color: #00bbdd;">    PUBLIC &quot;-//ibatis.apache.org//DTD SQL Map 2.0//EN&quot;</span>
<span style="color: #00bbdd;">    &quot;http://ibatis.apache.org/dtd/sql-map-2.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sqlMap</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;Libro&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;getLibro&quot;</span> <span style="color: #000066;">parameterClass</span>=<span style="color: #ff0000;">&quot;int&quot;</span> <span style="color: #000066;">resultClass</span>=<span style="color: #ff0000;">&quot;conexion.Libro&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    SELECT 
    id as id_libro,
    titulo as titulo_libro,
    autor as autor_libro,
    tematica as tematica_libro        
    FROM libros
    WHERE id = #value#
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;insert</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;introducirLibro&quot;</span> <span style="color: #000066;">parameterClass</span>=<span style="color: #ff0000;">&quot;conexion.Libro&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   INSERT INTO libros (id,titulo,autor,tematica) VALUES (#id_libro#,#titulo_libro#,#autor_libro#,#tematica_libro#)     
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/insert<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;getLibros&quot;</span> <span style="color: #000066;">resultClass</span>=<span style="color: #ff0000;">&quot;conexion.Libro&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   SELECT 
   id as id_libro,
   titulo as titulo_libro,
   autor as autor_libro,
   tematica as tematica_libro
   FROM libros         
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sqlMap<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>fichero de propiedades para el ejemplo, sustituye a lo que se hacia en el anterior ejemplo jdbc al cargar el driver</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/libros_jdbc
username=root
password=root</pre></td></tr></table></div>

<p>Fichero de configuración de Sql Map</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
</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 sqlMapConfig</span>
<span style="color: #00bbdd;">    PUBLIC &quot;-//ibatis.apache.org//DTD SQL Map Config 2.0//EN&quot;</span>
<span style="color: #00bbdd;">    &quot;http://ibatis.apache.org/dtd/sql-map-config-2.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sqlMapConfig<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;ibatisMap/sqlMapConfig.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;settings</span></span>
<span style="color: #009900;">    <span style="color: #000066;">cacheModelsEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">enhancementEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">lazyLoadingEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">maxRequests</span>=<span style="color: #ff0000;">&quot;32&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">maxSessions</span>=<span style="color: #ff0000;">&quot;10&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">maxTransactions</span>=<span style="color: #ff0000;">&quot;5&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">useStatementNamespaces</span>=<span style="color: #ff0000;">&quot;false&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transactionManager</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;JDBC&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;dataSource</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;SIMPLE&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> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JDBC.Driver&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${driver}&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> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JDBC.ConnectionURL&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${url}&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> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JDBC.Username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${username}&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> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JDBC.Password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${password}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataSource<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/transactionManager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sqlMap</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;ibatisMap/Libro.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;/sqlMapConfig<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Imagen de los jars utilizados</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/jars.png" alt="jars" title="jars" width="319" height="97" class="alignnone size-full wp-image-713" /> </p>
<p>Creamos una clase dentro del package conexion con el nombre BaseDatosIbatis.java</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
</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;">conexion</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Reader</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;">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;">com.ibatis.sqlmap.client.SqlMapClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.ibatis.sqlmap.client.SqlMapClientBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.ibatis.common.resources.Resources</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.PrintWriter</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;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Servlet implementation class for Servlet: BaseDatosIbatis
 *
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BaseDatosIbatis <span style="color: #000000; font-weight: bold;">extends</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span> <span style="color: #000000; font-weight: bold;">implements</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span>  SqlMapClient sqlMap <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> BaseDatosIbatis<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;">super</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: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">init</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>
			<span style="color: #003399;">String</span> recursos <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ibatisMap/SqlMapConfigLibro.xml&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Reader</span> leer <span style="color: #339933;">=</span> Resources.<span style="color: #006633;">getResourceAsReader</span><span style="color: #009900;">&#40;</span>recursos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			sqlMap <span style="color: #339933;">=</span> SqlMapClientBuilder.<span style="color: #006633;">buildSqlMapClient</span><span style="color: #009900;">&#40;</span>leer<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> <span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
	           <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;error mapeo: &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>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//mostramos el listado con el método get</span>
		response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//preparamos el objeto de salida</span>
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #666666; font-style: italic;">//creamos la salida </span>
&nbsp;
&nbsp;
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    
	    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Libros jdbc &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='imagen'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;img src='imagenes/registro.png' title='carpeta'/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;form action='BaseDatosIbatis' method='post'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Titulo&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='titulo'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Autor&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='autor'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Tematica&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='tematica'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input class='boton' type='submit' value='enviar'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/form&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>  	
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
		<span style="color: #003399;">String</span> titulo <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> autor <span style="color: #339933;">=</span>  request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> tematica <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
		response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><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;">//creamos el objeto libro</span>
		Libro libro <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Libro<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		libro.<span style="color: #006633;">setAutor_libro</span><span style="color: #009900;">&#40;</span>autor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		libro.<span style="color: #006633;">setTematica_libro</span><span style="color: #009900;">&#40;</span>tematica<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		libro.<span style="color: #006633;">setTitulo_libro</span><span style="color: #009900;">&#40;</span>titulo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		libro.<span style="color: #006633;">setId_libro</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: #666666; font-style: italic;">//insertamos en la base de datos el objeto libro</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span>
		<span style="color: #009900;">&#123;</span>
		    <span style="color: #666666; font-style: italic;">//insertamos los datos recibidos de </span>
			sqlMap.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;introducirLibro&quot;</span>, libro<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//recuperamos los datos de la base de datos</span>
			<span style="color: #003399;">List</span> <span style="color: #339933;">&lt;</span>Libro<span style="color: #339933;">&gt;</span> resultado <span style="color: #339933;">=</span>   sqlMap.<span style="color: #006633;">queryForList</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;getLibros&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//mostramos el resultado</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;&lt;title&gt;Mostramos los datos&lt;/title&gt;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Libros jdbc &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;table id='tabla'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;th&gt;titulo&lt;/th&gt;&lt;th&gt;autor&lt;/th&gt;&lt;th&gt;tematica&lt;/th&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Iterator</span> <span style="color: #339933;">&lt;</span>Libro<span style="color: #339933;">&gt;</span> iterador <span style="color: #339933;">=</span> resultado.<span style="color: #006633;">iterator</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;">while</span> <span style="color: #009900;">&#40;</span>iterador.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				Libro auxLibro <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Libro<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;
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='impar'&gt;&quot;</span><span style="color: #339933;">+</span>auxLibro.<span style="color: #006633;">getTitulo_libro</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='par'&gt;&quot;</span><span style="color: #339933;">+</span>auxLibro.<span style="color: #006633;">getAutor_libro</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='impar'&gt;&quot;</span><span style="color: #339933;">+</span>auxLibro.<span style="color: #006633;">getTematica_libro</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
			<span style="color: #009900;">&#125;</span>
&nbsp;
			 salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&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><span style="color: #003399;">SQLException</span> 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;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;error de consulta &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;
&nbsp;
	<span style="color: #009900;">&#125;</span>   	  	    
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/09/30/ibatis-proyecto-web-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaMail web eclipse</title>
		<link>http://www.railsymas.com/2009/09/25/javamail-web-eclipse/</link>
		<comments>http://www.railsymas.com/2009/09/25/javamail-web-eclipse/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 15:42:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=681</guid>
		<description><![CDATA[Java permite en sus aplicaciones web el envió de mensajes de correo electrónico Podemos importar librerías de java en la páginas jsp mediante el atributo import, para este ejemplo importamos las librerías javax.mail.* y seperadas por comas las demás Para hacer las pruebas depende de los parámetos de configuración de cada servidor de correo, protocolo [...]]]></description>
			<content:encoded><![CDATA[<p>Java permite en sus aplicaciones web el envió de mensajes de correo electrónico</p>
<p>Podemos importar librerías de java en la páginas jsp mediante el atributo import, para este ejemplo importamos las librerías javax.mail.*  y seperadas por comas las demás</p>
<p>Para hacer las pruebas depende de los parámetos de configuración de cada servidor de correo, protocolo smtp para enviar correos y pop para recibirlo.</p>
<p>Para descargar JavaMail, vamos a la dirección http://java.sun.com/products/javamail/downloads/index.html descargamos el zip y extraemos el fichero mail.jar par importarlo al directorio lib del proyecto web eclipse</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/mail.png" alt="mail" title="mail" width="147" height="49" class="alignnone size-full wp-image-686" /></p>
<p><span id="more-681"></span></p>
<p>los datos y campos de clave y contraseña estan genéricos para que cada uno los sustituya por los propios.</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
</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=ISO-8859-1&quot;</span>
    pageEncoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #339933;">%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ page <span style="color: #000000; font-weight: bold;">import</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javax.mail.*, java.util.*,javax.mail.internet.*&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=ISO-8859-1&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Prueba de correo<span style="color: #339933;">&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>h1<span style="color: #339933;">&gt;</span> Carga Correcta <span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;%</span>
  <span style="color: #003399;">Properties</span> propiedades <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Properties</span><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;">//insertamos la propiedades mail.smtp.host</span>
&nbsp;
  propiedades.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtp.host&quot;</span>,<span style="color: #0000ff;">&quot;smtp.correo.yahoo.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
  <span style="color: #666666; font-style: italic;">//creamos un objeto de session mail</span>
&nbsp;
  Session sesion <span style="color: #339933;">=</span> Session.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>propiedades<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//creamos un mensaje MimeMessage </span>
&nbsp;
  MimeMessage mensaje <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeMessage<span style="color: #009900;">&#40;</span>sesion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//dirección de correo electrónico</span>
&nbsp;
  InternetAddress de  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direccion@yahoo.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//establecemos el emisor del mensaje</span>
  mensaje.<span style="color: #006633;">setFrom</span><span style="color: #009900;">&#40;</span>de<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//direccion de correo electrónico del receptor</span>
  InternetAddress para <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;direccionyahoo@yahoo.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//establecemos el receptor del mensaje</span>
  mensaje.<span style="color: #006633;">addRecipient</span><span style="color: #009900;">&#40;</span>Message.<span style="color: #006633;">RecipientType</span>.<span style="color: #006633;">TO</span>,para<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//asunto del mensaje</span>
  mensaje.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Prueba de mensajeria en Java&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  mensaje.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hola mundo mail java&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
  <span style="color: #666666; font-style: italic;">//conexion al servidor de correo de yahoo</span>
&nbsp;
&nbsp;
  Transport transporte <span style="color: #339933;">=</span> sesion.<span style="color: #006633;">getTransport</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;smtp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  transporte.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;clave&quot;</span>,<span style="color: #0000ff;">&quot;contraseña&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">//el metodo send solamente vale para correo sin autenfificacion</span>
  transporte.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>mensaje,mensaje.<span style="color: #006633;">getAllRecipients</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  transporte.<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: #339933;">%&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;</span>p align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;</span>
  el correo ha sido enviado 
 <span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/correo.png" alt="correo" title="correo" width="596" height="294" class="alignnone size-full wp-image-683" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/09/25/javamail-web-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conexión a bases de datos J2ee jdbc eclipse</title>
		<link>http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/</link>
		<comments>http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 17:07:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[java j2ee]]></category>

		<guid isPermaLink="false">http://www.railsymas.com/?p=523</guid>
		<description><![CDATA[En este tutorial vamos a ver como configurar y crear un proyecto web en el editor eclipse para establecer una conexión con una base de datos. El ejemplo está realizado en linux ubuntu pero es igualmente utilizable para windows ya se comentó en anteriores post sobre el tema de instalaciones tanto del servidor tomcat como [...]]]></description>
			<content:encoded><![CDATA[<p>En este tutorial vamos a ver como configurar y crear un proyecto web en el editor eclipse para establecer una conexión con una base de datos.</p>
<p>El ejemplo está realizado en linux ubuntu pero es igualmente utilizable para windows ya se comentó en anteriores post sobre el tema de instalaciones tanto del servidor tomcat como del eclipse. </p>
<p>Como servidor de bases de datos utilizaremos mysql concretamente la versión<br />
mysql  Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using readline 5.2</p>
<p>Para crear la base de datos utilizaremos Mysql Query Browser, si teneís phpMyadmin instalado y os gusta más no hace falta utilizar esta herramienta o bien crearla desde el propio mysql.</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/MySQL-Query-Browser.png" alt="MySQL Query Browser" title="MySQL Query Browser" width="430" height="401" class="alignnone size-full wp-image-552" /></p>
<p><span id="more-523"></span></p>
<p>Esta aplicación hace lo mismo que haríamos con un terminal de mysql pero de una manera gráfica, nos pide el nombre del superusuario y la clave  por terminal sería (mysql -u root -p y darle la clave del usuario)</p>
<p>Una vez dentro vemos las bases de datos existentes en nuestro servidor mysql ( que viene por defecto con dos mysql e information_schema)</p>
<p>Crearemos una base de datos muy sencilla llamada &#8220;libros_jdbc&#8221;, con el cursor por ejemplo en la tabla &#8220;infomation_schema&#8221;, vamos a botón derecho y create chema y le damos el nombre anterior o el que se quiera (pero claro guardando entonces la correspondencia con lo siguiente )</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/bases.png" alt="bases" title="bases" width="215" height="161" class="alignnone size-full wp-image-554" /></p>
<p>Le damos el nombre a la base de datos<br />
<img src="http://www.railsymas.com/wp-content/uploads/2009/09/Create-Schema.png" alt="Create Schema" title="Create Schema" width="360" height="201" class="alignnone size-full wp-image-555" /></p>
<p>Esto mismo se puede hacer desde el terminal tanto de linux, como de símbolo de sistema de windows la instrucción sería la siguiente:</p>
<p>&#8220;create database libros_jdbc;&#8221;   y para para poder utilizarla (hacer tablas dentro de la base de datos ) ponemos<br />
&#8220;use libros_jdbc;&#8221;  con esto le estamos indicando a mysql que vamos a utilizar dicha base de datos.</p>
<p>Creamos una tabla para esta base de datos muy sencilla  </p>
<p>Le decimos que sea del tipo innodb aunque  no es necesario este paso para este ejemplo, las tablas de este formato permiten trabajar con claves externas para mysql5.</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/opciones.png" alt="opciones" title="opciones" width="570" height="210" class="alignnone size-full wp-image-559" /></p>
<p>para crear la tabla vamos a &#8220;Apply changes&#8221;,  si no hemos puesto el valor numérico del varchar lo editamos desde la ventana siguiente directamente.</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/tabla.png" alt="tabla" title="tabla" width="472" height="329" class="alignnone size-full wp-image-561" /></p>
<p>Descargamos el mysql jconnector segun la versión de mysql instalada,  como en este ejemplo esta instalado la versión 5.0, se descarga la versión de jconnector para esa versión. Podemos ver que existen varias versiones y para cada versión existe el correspondiente fichero para linux o windows</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/jconnector.png" alt="jconnector" title="jconnector" width="570" height="400" class="alignnone size-full wp-image-564" /></p>
<p>una vez descargado se descomprime el fichero dentro de la carpeta creada nos interesa importar solamente el fichero mysql-connector-java-5.0.8-bin.jar (el número depende de la versión de cada uno)</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/conector.png" alt="conector" title="conector" width="301" height="126" class="alignnone size-full wp-image-567" /></p>
<p>Creamos un nuevo proyecto web dinámico al igual que hacíamos en otros post y el directorio WebContent\WEB-INF\lib importamos el conector de bases de datos al igual que hacíamos con las imagenes en anteriores post.</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/importar.png" alt="importar" title="importar" width="348" height="159" class="alignnone size-full wp-image-569" /></p>
<p>Con esto solo ya funcionaría, pero en ocasiones eclipse nos muestra un error por no importar el jar en path del proyecto web</p>
<p>Botón derecho sobre el proyecto build path y configure build path y add external jar<br />
<img src="http://www.railsymas.com/wp-content/uploads/2009/09/path2.png" alt="path" title="path" width="570" height="271" class="alignnone size-full wp-image-575" /></p>
<p>creamos un package nuevo &#8220;conexion&#8221; y creamos un servlet nuevo llamado &#8220;basedatos&#8221; y  activamos los siguientes métodos en la creación del servlet</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/init.png" alt="init" title="init" width="414" height="229" class="alignnone size-full wp-image-584" /></p>
<p>resultado de introducir un nuevo registro visto desde el terminal con mysql</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/msqltabla1.png" alt="msqltabla" title="msqltabla" width="338" height="140" class="alignnone size-full wp-image-583" /></p>
<p>Realización de la conexión con un servlet, el método init del servlet se utiliza para para cargar los datos de la configuración del acceso a la base de datos antes de realizar cualquier operarción incluso este método puede recibir parámetros de configuración provenientes del fichero web.xml.</p>
<p>El servlet una vez cargado puede recibir peticiones get o post como habíamos explicado en anteriores post, cuando hacemos click con el botón derecho del ratón sobre el servlet run as ( o bien con el tomcat arrancado y http://localhost:8080/basedatos/basedatos siendo esto último nombre proyecto/servlet ).</p>
<p>Cuando se llama directamente interviene el método get y da como respuesta una página web con un formulario para introducir los campos para la tabla, esos campos se pasan al servlet mediante el método post y es entonces cuando se recogen los parámetros de la petición para establecer la inserción del registro en la tabla y la selección de los campos para la tabla.</p>
<p>Se obtiene el resultado en un objeto de la clase &#8220;ResultSet&#8221; y se itera por los registros mediante el método &#8220;next()&#8221;.</p>
<p>La salida por pantalla se pone la dtd para reconocimiento de la css y además los caracteres &#8220;\n&#8221; para ver el código html generado en el navegador de una forma escalonada.</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
</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;">conexion</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</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;">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;">java.io.PrintWriter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.DriverManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Statement</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Servlet implementation class for Servlet: basedatos
 *
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> basedatos <span style="color: #000000; font-weight: bold;">extends</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">http</span>.<span style="color: #006633;">HttpServlet</span> <span style="color: #000000; font-weight: bold;">implements</span> javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">Servlet</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Connection</span> conexion <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;">Statement</span> sentenciaSql <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;">ResultSet</span>  resultado <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> basedatos<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;">super</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: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
		<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">init</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>
			<span style="color: #003399;">String</span> controlador <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span>controlador<span style="color: #009900;">&#41;</span>.<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: #666666; font-style: italic;">//conectamos con la base de datos</span>
			conexion <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:mysql://localhost:3306/libros_jdbc&quot;</span>,<span style="color: #0000ff;">&quot;root&quot;</span>,<span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//creamos una sentencia sql</span>
			sentenciaSql <span style="color: #339933;">=</span> conexion.<span style="color: #006633;">createStatement</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;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">ClassNotFoundException</span> 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 pudo cargar el controlador&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;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">SQLException</span> 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;Excepcion sql&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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InstantiationException</span> 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;objeto no creado&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: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">IllegalAccessException</span> 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;Acceso ilegal&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>
	<span style="color: #009900;">&#125;</span>  
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
		response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</span><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;">//creamos la salida del html</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	    
	        salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Libros jdbc &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='imagen'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;img src='imagenes/registro.png' title='carpeta'/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;form action='basedatos' method='post'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Titulo&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='titulo'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Autor&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='autor'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;label&gt;Tematica&lt;/label&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input type='text' name='tematica'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;input class='boton' type='submit' value='enviar'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/form&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;br/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span>  	
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//recogemos la petición realizada por el usuario en el formulario</span>
		<span style="color: #003399;">String</span> valorTitulo <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;titulo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> valorAutor <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;autor&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> valorTematica <span style="color: #339933;">=</span> request.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tematica&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		response.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Text/html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">PrintWriter</span> salida <span style="color: #339933;">=</span> response.<span style="color: #006633;">getWriter</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>
			<span style="color: #666666; font-style: italic;">//metemos las cadenas con comas e insertamos los datos</span>
			sentenciaSql.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;insert into libros values (&quot;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;,'&quot;</span><span style="color: #339933;">+</span>valorTitulo<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">+</span>valorAutor<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;','&quot;</span><span style="color: #339933;">+</span>valorTematica<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;');&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//ejecutamos la sentencia de selección de los campos menos el id</span>
			resultado <span style="color: #339933;">=</span> sentenciaSql.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; SELECT titulo, autor, tematica  FROM libros;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//preparamos la salida para una nueva página</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;head&gt;&lt;title&gt;Mostramos los datos&lt;/title&gt;&lt;/head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		    salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;link rel='stylesheet' type='text/css' href='css/estilo.css'/&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;body&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='contenedor'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;h2&gt; Libros jdbc &lt;/h2&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;table id='tabla'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;th&gt;titulo&lt;/th&gt;&lt;th&gt;autor&lt;/th&gt;&lt;th&gt;tematica&lt;/th&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> resultado.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>   
&nbsp;
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='impar'&gt;&quot;</span><span style="color: #339933;">+</span>resultado.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='par'&gt;&quot;</span><span style="color: #339933;">+</span>resultado.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;td class='impar'&gt;&quot;</span><span style="color: #339933;">+</span>resultado.<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: #339933;">+</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/tr&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			   salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;div id='pie'&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt; www.railsymas.com &lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/body&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			   salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/html&gt;&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> 	<span style="color: #003399;">SQLException</span> e <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			salida.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Excepcion Sql : &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;
	<span style="color: #666666; font-style: italic;">/* (non-Javadoc)
	 * @see javax.servlet.GenericServlet#init()
	 */</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Fichero css utilizado</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
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#contenedor</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span>
&nbsp;
 <span style="color: #6666ff;">.boton</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#554444</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> 
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#imagen</span> <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#pie</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
     <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#424c56</span><span style="color: #00AA00;">;</span>  
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#pie</span> p <span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e6dfd5</span><span style="color: #00AA00;">;</span>
   <span style="color: #00AA00;">&#125;</span>
 <span style="color: #cc00cc;">#tabla</span> <span style="color: #00AA00;">&#123;</span> 
&nbsp;
  <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> 
&nbsp;
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
 <span style="color: #cc00cc;">#tabla</span> th <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#48a2b5</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
 td<span style="color: #6666ff;">.impar</span> <span style="color: #00AA00;">&#123;</span> 
&nbsp;
   <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#222</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e6dfd5</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
 td<span style="color: #6666ff;">.par</span>
  <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> 
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#554444</span><span style="color: #00AA00;">;</span> 
  <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Imagen formulario </p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/forjdbc.png" alt="forjdbc" title="forjdbc" width="565" height="541" class="alignnone size-full wp-image-591" /></p>
<p>imagen del proyecto </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2009/09/proyecto.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/09/proyecto.png" alt="" title="proyecto" width="282" height="485" class="alignnone size-full wp-image-1390" /></a></p>
<p>Imagen resultado</p>
<p><img src="http://www.railsymas.com/wp-content/uploads/2009/09/resultadostabla.png" alt="resultadostabla" title="resultadostabla" width="537" height="367" class="alignnone size-full wp-image-586" /></p>
<p>Enlace como crear un serlvet con eclipse y ejecutar desde el eclipse para encontrar recursos</p>
<p>Una vez instalado tomcat ( en windows es un ejecutable) en linux el enlace aquí</p>
<p><a href="http://www.railsymas.com/2008/12/01/instalacion-del-tomcat-en-el-eclipse/"> instalación tomcat</a></p>
<p>Un manejador de tomcat para elipse</p>
<p><a href="http://www.railsymas.com/2008/12/07/instalacion-de-tomcat-en-eclipse-para-linux/"> tomcat eclipse</a></p>
<p>Como crear un servlet con eclipse entro del eclipse</p>
<p><a href="http://www.railsymas.com/2009/07/21/servlets-j2ee-proyecto-web-eclipse/"> Crear un servlet </a></p>
<p>Ejecución de un servlet basesdatos </p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2009/09/a.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/09/a.png" alt="" title="a" width="272" height="49" class="alignnone size-full wp-image-1392" /></a></p>
<p><a href="http://www.railsymas.com/wp-content/uploads/2009/09/b.png"><img src="http://www.railsymas.com/wp-content/uploads/2009/09/b.png" alt="" title="b" width="795" height="144" class="alignnone size-full wp-image-1393" /></a></p>
<p>Al hacer new servlet, se crea la configuración automáticamente, algunas veces falla pero pocas</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
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><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;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		basedatos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-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-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>basedatos<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>
		conexion.basedatos<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;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<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>basedatos<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;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/basedatos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.railsymas.com/2009/09/09/conexion-a-bases-de-datos-j2ee-jdbc/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
