﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-eagames-随笔分类-Hibernate</title><link>http://www.blogjava.net/eagames/category/4044.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 12:17:10 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 12:17:10 GMT</pubDate><ttl>60</ttl><item><title>Struts+Spring+Hibernate练习</title><link>http://www.blogjava.net/eagames/archive/2005/11/22/21037.html</link><dc:creator>EA_Games</dc:creator><author>EA_Games</author><pubDate>Tue, 22 Nov 2005 13:40:00 GMT</pubDate><guid>http://www.blogjava.net/eagames/archive/2005/11/22/21037.html</guid><wfw:comment>http://www.blogjava.net/eagames/comments/21037.html</wfw:comment><comments>http://www.blogjava.net/eagames/archive/2005/11/22/21037.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eagames/comments/commentRss/21037.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eagames/services/trackbacks/21037.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">环境：<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Windows2003<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">jdk<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chsdate Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False" w:st="on">1.5.05</st1:chsdate><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">Eclipse3.1+MyEclipse4.03<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">做一登录练习。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">现已经完成了<SPAN lang=EN-US>login</SPAN>的<SPAN lang=EN-US>struts</SPAN>部份，实现了动态<SPAN lang=EN-US>ActionForm</SPAN>和动态<SPAN lang=EN-US>validator</SPAN>验证，详细全部文件内容如下：<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">struts-config.xml</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>&lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "<A href="http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><FONT color=#8d8c8c>http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd</FONT></A>"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;struts-config&gt;<BR>&nbsp; &lt;data-sources /&gt;<BR>&nbsp; &lt;form-beans &gt;<BR>&nbsp;&nbsp;&nbsp; &lt;form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form-property name="password" type="java.lang.String" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form-property name="username" type="java.lang.String" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/form-bean&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;/form-beans&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;global-exceptions /&gt;<BR>&nbsp; &lt;global-forwards &gt;<BR>&nbsp;&nbsp;&nbsp; &lt;forward name="indexGo" path="/index.jsp" /&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;/global-forwards&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;action-mappings &gt;<BR>&nbsp;&nbsp;&nbsp; &lt;action<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attribute="loginForm"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; input="/login.jsp"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name="loginForm"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path="/login"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scope="request"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; validate="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="com.test.struts.action.LoginAction" /&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;/action-mappings&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;message-resources parameter="com.test.struts.ApplicationResources" /&gt;<BR>&nbsp; &lt;plug-in className="org.apache.struts.validator.ValidatorPlugIn"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" /&gt;<BR>&nbsp; &lt;/plug-in&gt;<BR>&lt;/struts-config&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">login.jsp</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;%@ page language="java" contentType="text/html; charset=UTF-8"%&gt;<BR>&lt;%@ taglib uri="<A href="http://jakarta.apache.org/struts/tags-bean"><FONT color=#8d8c8c>http://jakarta.apache.org/struts/tags-bean</FONT></A>" prefix="bean"%&gt; <BR>&lt;%@ taglib uri="<A href="http://jakarta.apache.org/struts/tags-html"><FONT color=#8d8c8c>http://jakarta.apache.org/struts/tags-html</FONT></A>" prefix="html"%&gt;<BR>&nbsp;<BR>&lt;html&gt; <BR>&nbsp;&lt;head&gt;<BR>&nbsp;&nbsp;&lt;title&gt;JSP for loginForm form&lt;/title&gt;<BR>&nbsp;&lt;/head&gt;<BR>&nbsp;&lt;body&gt;<BR>&nbsp;&nbsp;&lt;html:form action="/login"&gt;<BR>&nbsp;&nbsp;&nbsp;username : &lt;html:text property="username"/&gt;&lt;html:errors property="username"/&gt;&lt;br/&gt;<BR>&nbsp;&nbsp;&nbsp;password : &lt;html:password property="password"/&gt;&lt;html:errors property="password"/&gt;&lt;br/&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;html:submit/&gt;&lt;html:cancel/&gt;<BR>&nbsp;&nbsp;&lt;/html:form&gt;<BR>&nbsp;&lt;/body&gt;<BR>&lt;/html&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">index.jsp</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;html&gt;<BR>&nbsp; &lt;head&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;title&gt;My JSP 'index.jsp' starting page&lt;/title&gt;<BR>&nbsp; &lt;/head&gt;<BR>&nbsp; <BR>&nbsp; &lt;body&gt;<BR>&nbsp;&lt;a href="login.jsp"&gt;Login&lt;/a&gt;<BR>&nbsp; &lt;/body&gt;<BR>&lt;/html&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">LoginAction.java</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">//Created by MyEclipse Struts<BR>// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_<st1:chsdate Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False" w:st="on">4.0.1</st1:chsdate>/xslt/JavaClass.xsl<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">package com.test.struts.action;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">import javax.servlet.http.HttpServletRequest;<BR>import javax.servlet.http.HttpServletResponse;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">import org.apache.struts.action.Action;<BR>import org.apache.struts.action.ActionForm;<BR>import org.apache.struts.action.ActionForward;<BR>import org.apache.struts.action.ActionMapping;<BR>import org.apache.struts.validator.DynaValidatorForm;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">/** <BR>&nbsp;* MyEclipse Struts<BR>&nbsp;* Creation date: 10-27-2005<BR>&nbsp;* <BR>&nbsp;* XDoclet definition:<BR>&nbsp;* @struts.action path="/login" name="loginForm" input="login.jsp" scope="request" validate="true"<BR>&nbsp;*/<BR>public class LoginAction extends Action {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;// --------------------------------------------------------- Instance Variables<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;// --------------------------------------------------------- Methods<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;/** <BR>&nbsp; * Method execute<BR>&nbsp; * @param mapping<BR>&nbsp; * @param form<BR>&nbsp; * @param request<BR>&nbsp; * @param response<BR>&nbsp; * @return ActionForward<BR>&nbsp; */<BR>&nbsp;public ActionForward execute(<BR>&nbsp;&nbsp;ActionMapping mapping,<BR>&nbsp;&nbsp;ActionForm form,<BR>&nbsp;&nbsp;HttpServletRequest request,<BR>&nbsp;&nbsp;HttpServletResponse response) {<BR>&nbsp;&nbsp;DynaValidatorForm loginForm = (DynaValidatorForm) form;<BR>&nbsp;&nbsp;// TODO Auto-generated method stub<BR>&nbsp;&nbsp;String username=(String)loginForm.get("username");<BR>&nbsp;&nbsp;String password=(String)loginForm.get("password");<BR>&nbsp;&nbsp;loginForm.set("password",null);<BR>&nbsp;&nbsp;if(username.equals("sonic")||password.equals("sonic")){<BR>&nbsp;&nbsp;&nbsp;System.out.println("AAA");<BR>&nbsp;&nbsp;&nbsp;return mapping.findForward("indexGo");<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;else {<BR>&nbsp;&nbsp;&nbsp;System.out.println("BBB");<BR>&nbsp;&nbsp;&nbsp;return mapping.getInputForward();<BR>&nbsp;&nbsp;}<BR>&nbsp;}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">ApplicationResources.properties</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">prompt.username=User Name<BR>prompt.password=User Password<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">errors.required={0} is required.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">ApplicationResources_zh_CN.properties</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">prompt.username=</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">用户名称<SPAN lang=EN-US><BR>prompt.password=</SPAN>登录密码<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">errors.required={0} </SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">是必须的<SPAN lang=EN-US>.<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">validation.xml</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;form-validation&gt;<BR>&nbsp;&lt;formset&gt;<BR>&nbsp;&nbsp;&lt;form name="loginForm"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;field property="username" depends="required"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg0 key="prompt.username" /&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/field&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;field property="password" depends="required"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;arg0 key="prompt.password" /&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/field&gt;<BR>&nbsp;&nbsp;&lt;/form&gt;<BR>&nbsp;&lt;/formset&gt;<BR>&lt;/form-validation&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">到此已经完成了全部代码！<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><img src ="http://www.blogjava.net/eagames/aggbug/21037.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eagames/" target="_blank">EA_Games</a> 2005-11-22 21:40 <a href="http://www.blogjava.net/eagames/archive/2005/11/22/21037.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts+Hibernate+Spring练习（续）</title><link>http://www.blogjava.net/eagames/archive/2005/11/22/21035.html</link><dc:creator>EA_Games</dc:creator><author>EA_Games</author><pubDate>Tue, 22 Nov 2005 13:39:00 GMT</pubDate><guid>http://www.blogjava.net/eagames/archive/2005/11/22/21035.html</guid><wfw:comment>http://www.blogjava.net/eagames/comments/21035.html</wfw:comment><comments>http://www.blogjava.net/eagames/archive/2005/11/22/21035.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eagames/comments/commentRss/21035.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eagames/services/trackbacks/21035.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">现在创建<SPAN lang=EN-US>spring</SPAN>框架<SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">配置<SPAN lang=EN-US>struts-config.xml</SPAN>文件，添加（<SPAN lang=EN-US>spring</SPAN>）的插件<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" /&gt;<BR>&nbsp; &lt;/plug-in&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">修改<SPAN lang=EN-US>LoginAction</SPAN>配置</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">原：</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;action<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attribute="loginForm"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; input="/login.jsp"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name="loginForm"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path="/login"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scope="request"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; validate="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="com.test.struts.action.LoginAction" /&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;/action-mappings&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">改为：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;action<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attribute="loginForm"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; input="/login.jsp"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name="loginForm"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path="/login"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scope="request"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; validate="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">org.springframework.web.struts.DelegatingActionProxy</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">" /&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp; &lt;/action-mappings&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">绿色字体部份为修改内容</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">这里将使用<SPAN lang=EN-US>spring</SPAN>的代理器来对<SPAN lang=EN-US>Action</SPAN>进行控制</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">当提交到<SPAN lang=EN-US>/login.do</SPAN>是将控制权交给了<SPAN lang=EN-US>spring</SPAN>，然后由<SPAN lang=EN-US>spring</SPAN>来决定是否转回到<SPAN lang=EN-US>struts</SPAN>的<SPAN lang=EN-US>Action<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">现在来配置<SPAN lang=EN-US>spring<o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><A href="http://www.springframework.org/dtd/spring-beans.dtd"><FONT color=#8d8c8c>http://www.springframework.org/dtd/spring-beans.dtd</FONT></A><SPAN style="COLOR: blue">"&gt;</SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;beans&gt;<BR>&nbsp;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;bean name="/login" class="net.xiaxin.action.LoginAction" singleton="false"&gt;&lt;/bean&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><BR>&lt;/beans&gt;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">绿色字体是关于转交控制权的配置内容</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">属性<SPAN lang=EN-US>singleton="false"</SPAN>，指明了<SPAN lang=EN-US>Action </SPAN>的实例获取方式为每次重新创建。解决了<SPAN lang=EN-US>Struts</SPAN>中令人诟病的线程安全问题（<SPAN lang=EN-US>Struts</SPAN>中，由一个<SPAN lang=EN-US>Action</SPAN>实例处理所有的请求，这就导致了类公用资源在并发请求中的线程同步问题。）（摘自<SPAN lang=EN-US>spring</SPAN>开发指南）<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">建立数据库在 </SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">这里我使用的是<SPAN lang=EN-US>mysql<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chsdate Year="1899" Month="12" Day="30" IsLunarDate="False" IsROCDate="False" w:st="on">4.1.1</st1:chsdate>x</SPAN></SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">CREATE TABLE `user` (<BR>&nbsp; `ID` int(11) NOT NULL auto_increment,<BR>&nbsp; `USERNAME` varchar(50) NOT NULL default '',<BR>&nbsp; `PASSWORD` varchar(50) NOT NULL default '',<BR>&nbsp; PRIMARY KEY&nbsp; (`ID`)<BR>) ENGINE=MyISAM DEFAULT CHARSET=latin1; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">创建<SPAN lang=EN-US>Hibernate</SPAN>框架</SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">使用<SPAN lang=EN-US>MyEclipse</SPAN>的数据<SPAN lang=EN-US>Database Explorer</SPAN>工具创建<SPAN lang=EN-US>User.hmb.xml</SPAN>、<SPAN lang=EN-US>AbstractUser.java</SPAN>、<SPAN lang=EN-US>User.java</SPAN>映射文件<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">创建完成后可以将自动生成的<SPAN lang=EN-US>hibernate.cfg.xml</SPAN>删除<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">创建<SPAN lang=EN-US>UserDAO.java</SPAN>、<SPAN lang=EN-US>UserDAOImp.java</SPAN></SPAN></B><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">修改<SPAN lang=EN-US>LoginAction.java</SPAN>文件</SPAN></B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">，使用<SPAN lang=EN-US>userDao</SPAN>的方法来进行用户验证<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">package com.test.struts.action;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">import javax.servlet.http.HttpServletRequest;<BR>import javax.servlet.http.HttpServletResponse;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">import org.apache.struts.action.Action;<BR>import org.apache.struts.action.ActionForm;<BR>import org.apache.struts.action.ActionForward;<BR>import org.apache.struts.action.ActionMapping;<BR>import org.apache.struts.validator.DynaValidatorForm;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">import com.test.UserDAO;</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><BR>public class LoginAction extends Action {<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><BR>&nbsp;<SPAN style="COLOR: green">private UserDAO userDAO</SPAN>;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;public UserDAO getUserDAO() {<BR>&nbsp;&nbsp;return userDAO;<BR>&nbsp;}</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;public void setUserDAO(UserDAO userDAO) {<BR>&nbsp;&nbsp;this.userDAO = userDAO;<BR>&nbsp;}</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;public ActionForward execute(ActionMapping mapping, ActionForm form,<BR>&nbsp;&nbsp;&nbsp;HttpServletRequest request, HttpServletResponse response) {<BR>&nbsp;&nbsp;DynaValidatorForm loginForm = (DynaValidatorForm) form;<BR>&nbsp;&nbsp;// TODO Auto-generated method stub<BR>&nbsp;&nbsp;String username = (String) loginForm.get("username");<BR>&nbsp;&nbsp;String password = (String) loginForm.get("password");<BR>&nbsp;&nbsp;loginForm.set("password", null);<BR>&nbsp;&nbsp;<SPAN style="COLOR: green">if (userDAO.isValidUser(username,password)) {<BR>&nbsp;&nbsp;&nbsp;return mapping.findForward("indexGo");<BR>&nbsp;&nbsp;} else {<BR>&nbsp;&nbsp;&nbsp;return mapping.getInputForward();<BR>&nbsp;&nbsp;}<BR></SPAN>&nbsp;}<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">}<BR></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">绿色字体为修改部份<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">现在剩下最后的<SPAN lang=EN-US>spring</SPAN>配置了<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "<A href="http://www.springframework.org/dtd/spring-beans.dtd"><FONT color=#8d8c8c>http://www.springframework.org/dtd/spring-beans.dtd</FONT></A>"&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&lt;beans&gt;<BR>&nbsp;&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;<BR>&nbsp;&nbsp;&lt;property name="driverClassName"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="url"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;value&gt;jdbc:mysql://localhost:3306/test&lt;/value&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="username"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;value&gt;root&lt;/value&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="password"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;value&gt;&lt;/value&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"&gt;<BR>&nbsp;&nbsp;&lt;property name="dataSource"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;ref local="dataSource" /&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="mappingResources"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;list&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;value&gt;com\test\Hibernate\User.hbm.xml&lt;/value&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/list&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="hibernateProperties"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;props&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;prop key="hibernate.dialect"&gt;net.sf.hibernate.dialect.MySQLDialect&lt;/prop&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/props&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;&lt;bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"&gt;<BR>&nbsp;&nbsp;&lt;property name="sessionFactory"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;ref local="sessionFactory" /&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;&lt;bean id="userDAO" class="com.test.UserDAOImp"&gt;<BR>&nbsp;&nbsp;&lt;property name="sessionFactory"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;ref local="sessionFactory" /&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;&lt;bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;<BR>&nbsp;&nbsp;&lt;property name="transactionManager"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;ref bean="transactionManager" /&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="target"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;ref local="userDAO" /&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&nbsp;&lt;property name="transactionAttributes"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;props&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;prop key="insert*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;prop key="get*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&lt;prop key="is*"&gt;PROPAGATION_REQUIRED,readOnly&lt;/prop&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;/props&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;&lt;bean name="/login" class="com.test.struts.action.LoginAction" singleton="false"&gt;<BR>&nbsp;&nbsp;&lt;property name="userDAO"&gt;<BR>&nbsp;&nbsp;&nbsp;&lt;ref bean="userDAOProxy" /&gt;<BR>&nbsp;&nbsp;&lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<BR>&lt;/beans&gt;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">&nbsp;<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-font-kerning: 0pt; mso-bidi-font-family: 宋体">现在可以进行测试了！<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></P><img src ="http://www.blogjava.net/eagames/aggbug/21035.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eagames/" target="_blank">EA_Games</a> 2005-11-22 21:39 <a href="http://www.blogjava.net/eagames/archive/2005/11/22/21035.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts1.2+Spring2.0+Hibernate3示例</title><link>http://www.blogjava.net/eagames/archive/2005/11/22/21034.html</link><dc:creator>EA_Games</dc:creator><author>EA_Games</author><pubDate>Tue, 22 Nov 2005 13:38:00 GMT</pubDate><guid>http://www.blogjava.net/eagames/archive/2005/11/22/21034.html</guid><wfw:comment>http://www.blogjava.net/eagames/comments/21034.html</wfw:comment><comments>http://www.blogjava.net/eagames/archive/2005/11/22/21034.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eagames/comments/commentRss/21034.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eagames/services/trackbacks/21034.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 工具：&nbsp;&nbsp;&nbsp;&nbsp;Eclipse3.1、MyEclipse4.03、Tomcat5.5.9、Properties Editor插件、MySql4.1.13&nbsp;新建工程：名称为 login&nbsp;创建Struts框架&nbsp;创建 index.jsp，增加一链接指向 login.jsp&nbsp;按下Ctrl + ...&nbsp;&nbsp;<a href='http://www.blogjava.net/eagames/archive/2005/11/22/21034.html'>阅读全文</a><img src ="http://www.blogjava.net/eagames/aggbug/21034.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eagames/" target="_blank">EA_Games</a> 2005-11-22 21:38 <a href="http://www.blogjava.net/eagames/archive/2005/11/22/21034.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>速动画教学系列共九集，关于struts、hibernate下载</title><link>http://www.blogjava.net/eagames/archive/2005/11/22/21032.html</link><dc:creator>EA_Games</dc:creator><author>EA_Games</author><pubDate>Tue, 22 Nov 2005 13:34:00 GMT</pubDate><guid>http://www.blogjava.net/eagames/archive/2005/11/22/21032.html</guid><wfw:comment>http://www.blogjava.net/eagames/comments/21032.html</wfw:comment><comments>http://www.blogjava.net/eagames/archive/2005/11/22/21032.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eagames/comments/commentRss/21032.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eagames/services/trackbacks/21032.html</trackback:ping><description><![CDATA[<H1 class=block_title><A id=viewpost1_TitleUrl HREF="/oksonic/articles/14140.html"><FONT color=#ff6600>速动画教学系列共九集，关于struts、hibernate</FONT></A></H1>
<DIV class=post>
<DIV class=postcontent><STRONG>速动画教程系列第一集 Struts入门</STRONG> 
<P>下载地址：</P>
<P><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"><FONT color=#8d8c8c>http://www.ereach.cn/download/MyEclipse-Struts-01.exe</FONT></A></P><STRONG>速动画教程系列第二集 Hibernate + Struts 实例</STRONG> 
<P>下载地址：</P>
<P><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"><FONT color=#8d8c8c>http://www.ereach.cn/download/MyEclipse_Hibernate.exe</FONT></A><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A></P>
<P><STRONG>速动画教程系列第三集 Struts 之 Hello Word 续</STRONG></P>
<P>实现了返回用户名称</P>
<P>下载地址：</P>
<P><A href="http://www.ereach.cn/download/struts_2.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/struts_2.rar</FONT></A><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A></P>
<P><STRONG>速动画教程系列第四集 Struts + Hibernate + oracle</STRONG></P>
<P>使用 MyEclipse 插件创建 Hibernate + Struts + oracle 实例</P>
<P>这一集是第二集的改版，数据库改为 oracle.</P>
<P>下载地址：</P>
<P><FONT color=#0000ff><A href="http://www.ereach.cn/download/Hibernate-Oracle.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/Hibernate-Oracle.rar</FONT></A><BR><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A><BR></P>
<P><STRONG><U>速动画教程系列第五集&nbsp;&nbsp;&nbsp; 第一段（共四段）&nbsp;地址薄综合实例</U></STRONG></P>
<P><U>使用Eclipse + MyEclipse + Struts + Hibernate + MySql </U></P>
<P><U>第一段下载地址：</U></P>
<P><FONT color=#0000ff><A href="http://www.ereach.cn/download/sonic005.1.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic005.1.rar</FONT></A><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A><BR><BR></P>
<P><STRONG><U>速动画教程系列第五集&nbsp;&nbsp;&nbsp; 第二段（共四段）&nbsp;地址薄综合实例</U></STRONG></P>
<P><U>使用Eclipse + MyEclipse + Struts + Hibernate + MySql </U></P>
<P><U>第一段下载地址：</U></P>
<P><FONT color=#0000ff><A href="http://www.ereach.cn/download/sonic005.2.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic005.2.rar</FONT></A><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A><BR><BR></P>
<P><STRONG><U>速动画教程系列第五集&nbsp;&nbsp;&nbsp; 第三段（共四段）&nbsp;地址薄综合实例</U></STRONG></P>
<P><U>使用Eclipse + MyEclipse + Struts + Hibernate + MySql </U></P>
<P><U>第一段下载地址：</U></P>
<P><A href="http://www.ereach.cn/download/sonic005.3.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic005.3.rar</FONT></A><A href="http://www.ereach.cn/download/sonic005.1.rar"></A><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A></P></FONT><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A></FONT><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A>
<P><STRONG><U>速动画教程系列第五集&nbsp;&nbsp;&nbsp; 第四段（共四段）&nbsp;地址薄综合实例</U></STRONG></P>
<P><U>使用Eclipse + MyEclipse + Struts + Hibernate + MySql </U></P>
<P><U>第一段下载地址：</U></P>
<P><A href="http://www.ereach.cn/download/sonic005.4.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic005.4.rar</FONT></A><BR><A href="http://www.ereach.cn/download/sonic005.1.rar"></A><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A></P></FONT><BR>
<P><STRONG>速动画教程第六集 Struts 之 Tiles 框架</STRONG></P>
<P>下载地址：<A href="http://www.ereach.cn/download/sonic006.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic006.rar</FONT></A><BR><A href="http://www.ereach.cn/download/sonic005.1.rar"></A><A href="http://www.ereach.cn/download/MyEclipse_Hibernate.exe"></A></P>
<P><BR><STRONG>速动画教程系列第七集 Eclipse+MyEclipse配置<BR></STRONG><A href="http://www.ereach.cn/download/sonic007.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic007.rar<BR></FONT></A></P>
<P><BR><STRONG>速动画教程第八集&nbsp;&nbsp; Hibernate的一对多关联关系</STRONG></P>
<P>下载地址：<A href="http://www.ereach.cn/download/sonic008.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic008.rar<BR></FONT></A><BR><BR></P>
<P><STRONG>速动画教程第九集 使用Eclipse+eclipseme开发HelloWorld!</STRONG></P>
<P>下载地址：<A href="http://www.ereach.cn/download/sonic009.rar"><FONT color=#8d8c8c>http://www.ereach.cn/download/sonic009.rar</FONT></A></P><A href="http://www.ereach.cn/download/MyEclipse-Struts-01.exe"></A></DIV></DIV><img src ="http://www.blogjava.net/eagames/aggbug/21032.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eagames/" target="_blank">EA_Games</a> 2005-11-22 21:34 <a href="http://www.blogjava.net/eagames/archive/2005/11/22/21032.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>配置WebLogic 8.1和Hibernate 3.0</title><link>http://www.blogjava.net/eagames/archive/2005/10/21/16361.html</link><dc:creator>EA_Games</dc:creator><author>EA_Games</author><pubDate>Fri, 21 Oct 2005 14:26:00 GMT</pubDate><guid>http://www.blogjava.net/eagames/archive/2005/10/21/16361.html</guid><wfw:comment>http://www.blogjava.net/eagames/comments/16361.html</wfw:comment><comments>http://www.blogjava.net/eagames/archive/2005/10/21/16361.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eagames/comments/commentRss/16361.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eagames/services/trackbacks/16361.html</trackback:ping><description><![CDATA[<P>最近，在 bartsandbox 上，有人问我在 WebLogic 上配置 Hibernate 的具体步骤。您可能知道， Hibernate 是一个非常流行的开源对象关系映射 (Object Relational Mapping ， ORM) 工具。下面是在 WebLogic 8.1 上配置 Hibernate 的具体步骤： </P>
<P>&nbsp; </P>
<P>?&nbsp; 首先要创建一个域。我创建了一个 WebLogic Workshop (WLW) 域，因为我打算使用 WLW 来创建和实现应用程序。 </P>
<P>?&nbsp; 将 hibernate...\lib\antlr-2.7.5H3.jar 添加到 PRE_CLASSPATH ，或者在 hibernate.cfg.xml 文件中将 query.factory_class 属性设为 user 2.x's query factory 。 </P>
<P>?&nbsp; WLW 域还启动了一个 PointBase 数据库实例。我将使用这个内置实例。我创建了一个新的用户和模式。并为该模式填充了一些示例数据。 </P>
<P>?&nbsp; 在服务器实例中配置连接池和数据源。 </P>
<P>?&nbsp; 创建应用程序。我打算使用 WebLogic Workshop 创建。 </P>
<P>?&nbsp; 应该将库（ jar 文件）（它们是成功运行 Hibernate 所必需的）放在哪里呢？放在应用程序的 APP-INF/lib 文件夹中。库包括 hibernate.jar 和附加的第三方库。引用 Hibernate Reference 的表格 3-1 。 </P>
<P>?&nbsp; 在 WLW 中创建一个 Java 项目。该 Java 项目包括映射到数据库的域类。 WLW 编译该项目，并将生成的 jar 文件放到 APP-INF/lib 目录下。在 Java 项目中编码域类。创建 Hibernate 映射文件和 Hibernate 配置文件。此外，从 Hibernate Reference 复制实现，创建 HibenateUtil 类。 Hibernate 配置文件包括数据源的 JNDI 名。 </P>
<P>?&nbsp; 创建一个 EJB 对象（例如，一个模块）。该项目包含了会话 bean 。编写一个操纵域类的会话 bean 。 </P>
<P>?&nbsp; 创建一个 Web 或 Web Service 项目（例如，一个模块）。该项目包含了可互操作性地测试会话 bean 的组件。 </P>
<P>完整、有效、自包含的示例应用程序 在此 。其中包括了模式和所有的 Hibernate 配置文件。（注：需要有 bartsandbox 的免费会员资格。） </P>
<P>接下来的文章中，我将增强这一基本配置。<BR>我的 前一篇文章 描述了在 WebLogic 8.1 上配置 Hibernate 3.0 的具体步骤。文章引起了巨大的反响。在本文中，我将介绍高级配置，其中 Hibernate 使用了 WebLogic 的 Java 命名和目录接口 (Java Naming and Directory Interface ， JNDI) 、 Java 事务 API (Java Transaction API ， JTA) 、 Java 连接器架构 (Java Connector Architecture ， JCA) 和 Java 管理扩展 (Java Management extension ， JMX) 实现。 </P>
<P>我们先从 JNDI 开始。通过在 hibernate.cfg.xml 文件中命名 SessionFactory ， Hibernate 使 SessionFactory 在 JNDI 中可用。呀！这在 WebLogic 中不起作用。正如 此处 所描述的， WebLogic JNDI 与 Hibernate 配合得不是很好。有多个工作区。工作区手动将 SessionFactory 绑定到 JNDI 中，方法是通过 WebLogic startup 类或者启动 servlet 。但是，我不能使 SessionFactory 实例从 JNDI 安全返回。因此，折衷一下，为 SessionFactory 向 HibernateUtil 实用类添加一个存取器。 </P>
<P>为了配置 Hibernate 使用 JTA ，我在 hibernate.cfg.xml 文件中配置了 transaction.factory_class 。有两个选项： org.hibernate.transaction.JTATransactionFactory 和 org.hibernate.transaction.CMTTransactionFactory 。说明文档建议，对 Bean 托管事务界定 (Bean Managed Transaction Demarcation ， BMTD) bean 使用 JTATransactionFactory ，而对容器托管事务界定 (Container Managed Transaction Demarcation ， CMTD) bean 使用 CMTTransactionFactory 。 JTATransactionFactory 似乎更通用些，它既支持 BMTD bean 又支持 CMTD bean 。因此，我配置的是 JTATransactionFactory 。此外，为了以特定于容器的方式查找事务，我在 hibernate.cfg.xml 文件中配置了 transaction.manager_lookup_class 。借助于这个配置，我完全不需要使用 Hibernate Transaction API 。 </P>
<P>对 Hibernate 的 JCA 支持是实验性质的，目前还没有全面应用于 WebLogic 。我可以设想，以后 Hibernate 会被打包为 Resource ARchive (RAR) 文件。 Hibernate RAR 文件作为资源适配器部署。适配器使 Session 在 JNDI 中可用。所有的配置元素都是通过资源适配器（ xml 文件）配置的，而不是通过 hibernate.cfg.xml 文件或采用其他方法配置。为什么在 WebLogic 中要配置 Hibernate 使用 JCA ？ JCA 旨在封装传统系统的连接、事务等等，并使它们在 J2EE 中可用。但是，由于 Hibernate ，传统的资源适配器的优势不能全面体现。一旦 Hibernate 被配置为资源适配器，特定的应用程序与 Hibernate 的耦合就被削弱了。多个不同的应用程序可以使用同一个 Hibernate 资源适配器。由于当前正在开发的 EJB 3.0 ，这种配置在 EJB 的持久性 API 、 Hibernate 和 Java 数据对象 (Java Data Object ， JDO) 的标准化方面的优势更为明显。从理论上讲，可以热部署（或重部署）适配器和改变持久性实现。 </P>
<P>Hibernate 附带 JMX Management Bean (MBean) 实现。我不知道如何使用 JMX 将 Hibernate 部署到 WebLogic 上。 Hibernate 和 WebLogic 使用 JMX 有什么好处？至少有两条。一条是部署和重部署。更重要的一条是，可以监控 Hibernate 和获得的统计信息。从 JMX 控制台进行运行时监控是所部署的应用程序运行良好的基本保障。 </P>
<P>我更新了示例应用程序，可 在此 获取。（注：需要有 bartsandbox 的免费会员资格。） </P>
<P>&nbsp;</P><img src ="http://www.blogjava.net/eagames/aggbug/16361.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eagames/" target="_blank">EA_Games</a> 2005-10-21 22:26 <a href="http://www.blogjava.net/eagames/archive/2005/10/21/16361.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate 入门</title><link>http://www.blogjava.net/eagames/archive/2005/10/21/16349.html</link><dc:creator>EA_Games</dc:creator><author>EA_Games</author><pubDate>Fri, 21 Oct 2005 14:16:00 GMT</pubDate><guid>http://www.blogjava.net/eagames/archive/2005/10/21/16349.html</guid><wfw:comment>http://www.blogjava.net/eagames/comments/16349.html</wfw:comment><comments>http://www.blogjava.net/eagames/archive/2005/10/21/16349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/eagames/comments/commentRss/16349.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/eagames/services/trackbacks/16349.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>Hibernate </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">入门（</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN><SPAN lang=EN-US><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">本文配置环境：</SPAN><SPAN lang=EN-US> <BR>JBuilder X <BR>jdk 1.4.2 <BR>Mysql 4.0.11 </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">驱动</SPAN><SPAN lang=EN-US>:mm.mysql-2.0.4-bin.jar(org.gjt.mm.mysql.Driver) <BR>Hibernate 2.1 <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">解压</SPAN><SPAN lang=EN-US>Hibernate <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开</SPAN><SPAN lang=EN-US>JB</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，新建工程，名为：</SPAN><SPAN lang=EN-US>hibernate <BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">加入</SPAN><SPAN lang=EN-US>Hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">需要的包与</SPAN><SPAN lang=EN-US>MYSQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">驱动</SPAN><SPAN lang=EN-US> <BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">步骤</SPAN><SPAN lang=EN-US>:file-&gt;new project-&gt;name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中输入</SPAN><SPAN lang=EN-US>hibernate,directory</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">选择你要存放本工程的路径</SPAN><SPAN lang=EN-US>-&gt;next <BR><BR>-&gt;required libraries-&gt;add-&gt;new-&gt;name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中输入你要设置的</SPAN><SPAN lang=EN-US>hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">包名</SPAN><SPAN lang=EN-US> <BR><BR>-&gt;add-&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">选择你</SPAN><SPAN lang=EN-US>hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">解压到的目录，选中该目录下的</SPAN><SPAN lang=EN-US>hibernate2.jar</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>lib</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下的所有</SPAN><SPAN lang=EN-US>jar</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">包，再把你的</SPAN><SPAN lang=EN-US>MYSQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">驱动包也加进去</SPAN><SPAN lang=EN-US> <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后一直按</SPAN><SPAN lang=EN-US>OK</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>next</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN><SPAN lang=EN-US> <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">新建一个类</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">名为</SPAN><SPAN lang=EN-US>Hello_Bean.java,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码如下：</SPAN><SPAN lang=EN-US> <BR><BR><BR><BR>package hibernate; <BR><BR>import java.io.Serializable; <BR><BR>/** <BR>* @author geezer <BR>* QQ:9986986 MSN:geezer_hot@hotmail.com <BR>*/ <BR><BR>public class Hello_Bean implements Serializable { <BR><BR>private String name;//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>address</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>id</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的名字可以自己定，不会有什么影响</SPAN><SPAN lang=EN-US>.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">但</SPAN><SPAN lang=EN-US>get</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>set</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法不可以。因为那得跟数据库与配置文件对应。</SPAN><SPAN lang=EN-US> <BR><BR>private String address; <BR><BR>private int id; <BR><BR><BR><BR>public Hello_Bean() { <BR><BR>} <BR><BR>public Hello_Bean(String name, String address) {//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">构造函数</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">看完本章以后相信你会明白的了</SPAN><SPAN lang=EN-US> <BR>this.name = name; <BR>this.address = address; <BR>} <BR><BR>public String getName() {//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此方法名必须与</SPAN><SPAN lang=EN-US>Hello_Bean.hbm.xml</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件里的对应的名字一样，下面会详细讲</SPAN><SPAN lang=EN-US> <BR>return name; <BR>} <BR><BR>public void setName(String name) { <BR>this.name = name; <BR>} <BR><BR>public String getAddress() { <BR>return address; <BR>} <BR><BR>public void setAddress(String address) { <BR>this.address = address; <BR>} <BR><BR>public int getId() {//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">必须的方法</SPAN><SPAN lang=EN-US> <BR>return id; <BR>} <BR><BR>public void setId(int id)//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">必须的方法</SPAN><SPAN lang=EN-US> <BR>{ <BR>this.id = id; <BR>} <BR><BR><BR>} <BR><BR><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">完成这一步以后编译</SPAN><SPAN lang=EN-US> <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">将</SPAN><SPAN lang=EN-US>hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">解压后的目录下的</SPAN><SPAN lang=EN-US>src</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件夹里的</SPAN><SPAN lang=EN-US>hibernate.properties</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>log4j.properties</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件复制到你的工程目录的</SPAN><SPAN lang=EN-US>classes</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下</SPAN><SPAN lang=EN-US> <BR><BR>(</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">例如</SPAN><SPAN lang=EN-US>hibernate\classes\</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下</SPAN><SPAN lang=EN-US>)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US> <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开</SPAN><SPAN lang=EN-US>hibernate.properties</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件，找到</SPAN><SPAN lang=EN-US> <BR><BR>## HypersonicSQL <BR><BR>hibernate.dialect net.sf.hibernate.dialect.HSQLDialect <BR>hibernate.connection.driver_class org.hsqldb.jdbcDriver <BR>hibernate.connection.username sa <BR>hibernate.connection.password <BR>hibernate.connection.url jdbc:hsqldb:hsql://localhost <BR>hibernate.connection.url jdbc:hsqldb:test <BR>hibernate.connection.url jdbc:hsqldb:. <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">改为</SPAN><SPAN lang=EN-US> <BR><BR>## HypersonicSQL <BR><BR>#hibernate.dialect net.sf.hibernate.dialect.HSQLDialect <BR>#hibernate.connection.driver_class org.hsqldb.jdbcDriver <BR>#hibernate.connection.username sa <BR>#hibernate.connection.password <BR>#hibernate.connection.url jdbc:hsqldb:hsql://localhost <BR>#hibernate.connection.url jdbc:hsqldb:test <BR>#hibernate.connection.url jdbc:hsqldb:. <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">再找到</SPAN><SPAN lang=EN-US> <BR><BR>## MySQL <BR><BR>#hibernate.dialect net.sf.hibernate.dialect.MySQLDialect <BR>#hibernate.connection.driver_class org.gjt.mm.mysql.Driver <BR>#hibernate.connection.driver_class com.mysql.jdbc.Driver <BR>#hibernate.connection.url jdbc:mysql:///test <BR>#hibernate.connection.username root <BR>#hibernate.connection.password <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">改为</SPAN><SPAN lang=EN-US> <BR><BR><BR>## MySQL <BR><BR>hibernate.dialect net.sf.hibernate.dialect.MySQLDialect <BR>hibernate.connection.driver_class org.gjt.mm.mysql.Driver <BR>hibernate.connection.url jdbc:mysql://localhost:3306/test <BR>hibernate.connection.username root <BR>hibernate.connection.password <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上面的</SPAN><SPAN lang=EN-US>URL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">请改为你自己的。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US>&nbsp;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">完成以后创建一个空的文件，保存在你工程的类文件同个文件夹里（例如</SPAN><SPAN lang=EN-US>hibernate\classes\hibernate\</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下），文件名为：</SPAN><SPAN lang=EN-US>Hello_Bean.hbm.xml <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">内容如下：</SPAN><SPAN lang=EN-US> <BR><BR>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <BR><BR>&lt;!DOCTYPE hibernate-mapping PUBLIC <BR>"-//Hibernate/Hibernate Mapping DTD 2.0//EN" <BR>"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"&gt; <BR>&lt;hibernate-mapping&gt; <BR><BR>&lt;class name="hibernate.Hello_Bean" table="test_hibernate" &gt; <BR><BR>&lt;id name="id" column="id"&gt; <BR><BR>&lt;generator class="identity"/&gt; <BR><BR>&lt;/id&gt; <BR><BR>&lt;property name="name" type="string" update="true" insert="true" column="name" /&gt; <BR>&lt;property name="address" type="string" update="true" insert="true" column="address" /&gt; <BR><BR>&lt;/class&gt; <BR><BR>&lt;/hibernate-mapping&gt; <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">稍微解释一下</SPAN><SPAN lang=EN-US>,&lt;class name="hibernate.Hello_Bean" table="test_hibernate" &gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里的</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">指你的生成表的类，</SPAN><SPAN lang=EN-US> <BR><BR>table</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">则指定你要创建的数据库表的名字，可以自由修改，没有影响</SPAN><SPAN lang=EN-US>. <BR><BR>&lt;id name="id" column="id"&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置主键</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，这里</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值</SPAN><SPAN lang=EN-US>id</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">跟</SPAN><SPAN lang=EN-US>Hello_Bean.java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里的方法</SPAN><SPAN lang=EN-US>getId</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>setId</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对应，不用管这个</SPAN><SPAN lang=EN-US>,hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">会自动调用，配置好就可以了，</SPAN><SPAN lang=EN-US>column</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值为要生成的字段名，可以自由修改，没有影响。</SPAN> <SPAN lang=EN-US><BR><BR>&lt;generator class="identity"/&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性让主键的</SPAN><SPAN lang=EN-US>ID</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">自增（插入数据的时候自动加</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）</SPAN><SPAN lang=EN-US> <BR><BR>&lt;property name="name" type="string" update="true" insert="true" column="name" /&gt;</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里的</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值</SPAN><SPAN lang=EN-US>"name"</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">跟</SPAN><SPAN lang=EN-US>Hello_Bean.java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里的</SPAN><SPAN lang=EN-US>getName</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法对应，</SPAN><SPAN lang=EN-US>column</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为要生成的字段名</SPAN><SPAN lang=EN-US> <BR>&lt;property name="address" type="string" update="true" insert="true" column="address" /&gt; <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">分别添加一个字段</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>address</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，注意这里的</SPAN><SPAN lang=EN-US>type</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性类型为</SPAN><SPAN lang=EN-US>string,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果这里的类型与</SPAN><SPAN lang=EN-US>Hello_Bean.java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里设置的类型不一样会出错。</SPAN><SPAN lang=EN-US> <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">修改完以后保存。</SPAN><SPAN lang=EN-US> <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最后在</SPAN><SPAN lang=EN-US>JB</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里新建一个类，名字为</SPAN><SPAN lang=EN-US>Hello.java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，我会一步步解释，代码如下：</SPAN><SPAN lang=EN-US><BR><BR>package hibernate; <BR><BR>import net.sf.hibernate.cfg.Configuration; <BR>import net.sf.hibernate.SessionFactory; <BR>import net.sf.hibernate.tool.hbm2ddl.SchemaExport; <BR>import net.sf.hibernate.Session; <BR>import net.sf.hibernate.Query; <BR>import net.sf.hibernate.Hibernate; <BR>import net.sf.hibernate.type.LongType; <BR>import net.sf.hibernate.Transaction; <BR>import net.sf.hibernate.ScrollableResults; <BR>import java.util.*; <BR><BR>/** <BR>* @author geezer <BR>* QQ:9986986 MSN:geezer_hot@hotmail.com <BR>*/ <BR><BR><BR>public class Hello { <BR><BR><BR>public Hello() { <BR><BR><BR>} <BR><BR>public static void main(String[] args) throws Exception { <BR><BR>Configuration cfg = new Configuration().addClass(Hello_Bean.class);//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用</SPAN><SPAN lang=EN-US>Hello_Bean.class</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类初始化</SPAN><SPAN lang=EN-US> <BR><BR>SessionFactory sessions = cfg.buildSessionFactory();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用</SPAN><SPAN lang=EN-US>buildSessionFactory</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法得到一个</SPAN><SPAN lang=EN-US>SessionFactory</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象</SPAN><SPAN lang=EN-US> <BR><BR>Session session = sessions.openSession();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">再用</SPAN><SPAN lang=EN-US>SessionFactory</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>openSession</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法得到一个</SPAN><SPAN lang=EN-US>session <BR><BR>new SchemaExport(cfg).create(true, true);//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这句意思是创建表，第一次运行以后，就是创建完表以后再把这行加上注释。如果建表以后不把这一句注释掉的话会删掉以前创建的表再重新建一个。</SPAN><SPAN lang=EN-US><BR><BR>Hello_Bean my_hibernate = new Hello_Bean();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">得到一个</SPAN><SPAN lang=EN-US>Hello_Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象</SPAN><SPAN lang=EN-US> <BR><BR>my_hibernate.setName("my_name");//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置</SPAN><SPAN lang=EN-US>Hello_Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">值为</SPAN><SPAN lang=EN-US>my_name,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里其实就是说把字符串</SPAN><SPAN lang=EN-US>my_name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当作数据库字段</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值</SPAN><SPAN lang=EN-US>.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">数据库字段</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>Hello_Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类里的</SPAN><SPAN lang=EN-US>getName,setName</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法是对应的。形成一个映射关系。</SPAN><SPAN lang=EN-US> <BR><BR>my_hibernate.setAddress("my_address");//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如上</SPAN><SPAN lang=EN-US> <BR><BR>session.save(my_hibernate);//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这句很重要，将</SPAN><SPAN lang=EN-US>my_hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象写进数据库（</SPAN><SPAN lang=EN-US>my_hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象里的</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与</SPAN><SPAN lang=EN-US>address</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们刚刚已经设置了值了，会直接把</SPAN><SPAN lang=EN-US>name,address</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值写进数据库去）</SPAN><SPAN lang=EN-US> <BR><BR>session.flush(); <BR>session.close(); <BR><BR><BR>//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上面是一个简单的插入数据与第一次运行建表的介绍，下面我再介绍删除与修改的方法</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下面的代码我都加了注释，自己需要什么方法（删除，修改，循环数据库的值）就把注释去掉就可以了</SPAN><SPAN lang=EN-US> <BR>HSQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">比较简单，大家看一下例子就应该明白了，这里就不讲了。</SPAN><SPAN lang=EN-US> <BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">遍历数据库的方法有三种，分别是</SPAN><SPAN lang=EN-US>Query,find,iterate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，</SPAN><SPAN lang=EN-US>Query</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>find</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回一个</SPAN><SPAN lang=EN-US>List</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口，</SPAN><SPAN lang=EN-US>iterate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回一个</SPAN><SPAN lang=EN-US>Iterator</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，具体方法可以查看这些类得知。</SPAN><SPAN lang=EN-US> <BR><BR>//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">删除数据</SPAN><SPAN lang=EN-US> <BR>/* <BR>int a=session.delete("from Hello_Bean where id=1");//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果没有找到</SPAN><SPAN lang=EN-US>id</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的数据那么返回</SPAN><SPAN lang=EN-US>0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，如果找到返回</SPAN><SPAN lang=EN-US>1,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里的</SPAN><SPAN lang=EN-US>Hello_Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是我们的</SPAN><SPAN lang=EN-US>Hello_Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类，他跟数据库表对应，所以我们在这里是直接用</SPAN><SPAN lang=EN-US>Hello_Bean</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">来代码数据库表的。</SPAN><SPAN lang=EN-US> <BR>System.out.println(a); <BR>session.flush(); <BR>session.close(); <BR><BR>*/ <BR><BR>//Query</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法查询数据</SPAN><SPAN lang=EN-US> <BR>/* <BR>Hello_Bean my_hibernate = null; <BR>Query q = session.createQuery("from Hello_Bean"); <BR>// Query q = session.createQuery("from Hello_Bean where name=?");//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里的</SPAN><SPAN lang=EN-US>?</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">跟</SPAN><SPAN lang=EN-US>JDBC</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>PreparedStatement</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法的差不多，只不过这里的是以</SPAN><SPAN lang=EN-US>0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开始，</SPAN><SPAN lang=EN-US>jdbc</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的是</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">开始。</SPAN><SPAN lang=EN-US> <BR>// q.setString(0,"my_name"); <BR>// q.setFirstResult(0);//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这句话的意思是说查询结果从第几行开始列出数据</SPAN> <SPAN lang=EN-US><BR>// q.setMaxResults(3);//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这句话的意思是取多少条数据，就跟</SPAN><SPAN lang=EN-US>SQL SERVER</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>TOP</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法和</SPAN><SPAN lang=EN-US>MYSQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>LIMIT</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法一样的意思。</SPAN><SPAN lang=EN-US> <BR>// ScrollableResults sc=q.scroll();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">得到一个</SPAN><SPAN lang=EN-US>ScrollableResults,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可滚动的，如果你的数据库支持游标自由移动的话可以加上，也就是说可以判断查询结果有没有值，或者移动到下一行记录等等。</SPAN><SPAN lang=EN-US> <BR><BR>// if(!sc.next()) <BR>// { <BR>// System.out.println("</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">没有找到你需要的数据</SPAN><SPAN lang=EN-US>"); <BR>// } <BR><BR>session.flush();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果使用了</SPAN><SPAN lang=EN-US>ScrollableResults</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的话请把这行注释掉</SPAN><SPAN lang=EN-US> <BR>session.close();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果使用了</SPAN><SPAN lang=EN-US>ScrollableResults</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的话请把这行注释掉</SPAN><SPAN lang=EN-US> <BR><BR>List l=q.list();//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">返回一个</SPAN><SPAN lang=EN-US>List</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口，用来遍历结果集</SPAN><SPAN lang=EN-US> <BR><BR>for(int i=0;i&lt;l.size();i++){ <BR>my_hibernate = (Hello_Bean) l.get(i);//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">从</SPAN><SPAN lang=EN-US>List</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中取得一个</SPAN><SPAN lang=EN-US>my_hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象</SPAN><SPAN lang=EN-US> <BR>System.out.println(my_hibernate.getName());//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">调用</SPAN><SPAN lang=EN-US>my_hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象的</SPAN><SPAN lang=EN-US>getName</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法取得数据库</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">字段的值</SPAN><SPAN lang=EN-US> <BR><BR>} <BR><BR>*/ <BR><BR>//find</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法查询数据</SPAN><SPAN lang=EN-US> <BR>/* <BR>Hello_Bean my_hibernate = null; <BR>List q = session.find("from Hello_Bean"); <BR>session.flush(); <BR>session.close(); <BR><BR>for(int i=0;i&lt;q.size();i++) <BR>{ <BR>my_hibernate = (Hello_Bean) q.get(i); <BR>System.out.println(my_hibernate.getName()); <BR>} <BR>*/ <BR><BR>//iterate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法查询数据</SPAN><SPAN lang=EN-US> <BR>/* <BR>Hello_Bean my_hibernate = null; <BR>Iterator q = session.iterate("from Hello_Bean"); <BR><BR>while(q.hasNext()) <BR>{ <BR>my_hibernate = (Hello_Bean) q.next(); <BR>System.out.println(my_hibernate.getName()); <BR>} <BR><BR>*/ <BR><BR>//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">修改数据</SPAN><SPAN lang=EN-US> <BR>/* <BR>Query qq=session.createQuery("from Hello_Bean"); <BR><BR>Hello_Bean my_hibernate=(Hello_Bean)session.load(Hello_Bean.class,new Integer(2)); <BR>//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这里的</SPAN><SPAN lang=EN-US>new Integer(2)</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">意思是修改表中</SPAN><SPAN lang=EN-US>id</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的那一行数据</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">必须是一个包装类的对象，如果使用</SPAN><SPAN lang=EN-US>int</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的话会出错。</SPAN><SPAN lang=EN-US> <BR>my_hibernate.setName("geezer");//</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">把</SPAN><SPAN lang=EN-US>id</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的那一行数据的</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">字段值改为</SPAN><SPAN lang=EN-US>"geezer" <BR>session.flush(); <BR>session.close(); <BR><BR>*/ <BR><BR>} <BR><BR>} <BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">最后运行就可以了。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果大家有什么不清楚的，可以下载这篇文章的例子看看，运行一下。</SPAN><SPAN lang=EN-US> <BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下载地址：</SPAN><SPAN lang=EN-US><A href="http://www.ddvip.net/program/java/index10/img_java_s/hibernate_demo.rar"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT color=#000066>点击下载</FONT></SPAN></A><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">下载完以后用</SPAN><SPAN lang=EN-US>JB</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">打开</SPAN><SPAN lang=EN-US>hibernate.jpx</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就可以了。用之前把</SPAN><SPAN lang=EN-US>hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>MYSQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的驱动加进去，方法如果不知道再看看本章开头部分。</SPAN><SPAN lang=EN-US> <BR><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">常见错误：</SPAN><SPAN lang=EN-US> <BR>Caused by: org.dom4j.DocumentException: Invalid byte 2 of 2-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 2-byte UTF-8 sequence. <BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果出现这行错误说明你的</SPAN><SPAN lang=EN-US>xml</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置文件有不规范的字符，检查下。</SPAN><SPAN lang=EN-US> <BR><BR>net.sf.hibernate.MappingException: Error reading resource: hibernate/Hello_Bean.hbm.xml <BR><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果出现这行错误说明你的</SPAN><SPAN lang=EN-US>hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>XML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置文件有错</SPAN><SPAN lang=EN-US> <BR><BR>net.sf.hibernate.MappingException: Resource: hibernate/Hello_Bean.hbm.xml not found <BR><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果出现这行错误说明</SPAN><SPAN lang=EN-US>hibernate</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的</SPAN><SPAN lang=EN-US>XML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配置文件没有找到，你应该把</SPAN><SPAN lang=EN-US>XML</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件放在与你的类文件同个目录下</SPAN><SPAN lang=EN-US>,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">本文中是放在</SPAN><SPAN lang=EN-US>hibernate\classes\hibernate\</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">目录下，也就是跟</SPAN><SPAN lang=EN-US>Hello_Bean.class</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类文件一起。</SPAN><SPAN lang=EN-US> <BR><BR>net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property name in class hibernate.Hello_Bean <BR><BR><BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果出现这行错误说明你的</SPAN><SPAN lang=EN-US>xml</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文件里设置的字段名</SPAN><SPAN lang=EN-US>name</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的值与</SPAN><SPAN lang=EN-US>Hello_Bean.java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类里的</SPAN><SPAN lang=EN-US>getXXX</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或</SPAN><SPAN lang=EN-US>setXXX</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法不一致。</SPAN><SPAN lang=EN-US> <BR><BR>net.sf.hibernate.HibernateException: JDBC Driver class not found: org.gjt.mm.mysql.Driver <BR></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果出现这行错误说明你的</SPAN><SPAN lang=EN-US>MYSQL</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">驱动没有加进</SPAN><SPAN lang=EN-US>JB</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">库里或者不在</SPAN><SPAN lang=EN-US>CLASSPATH</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里。（全文完）</SPAN></P><img src ="http://www.blogjava.net/eagames/aggbug/16349.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/eagames/" target="_blank">EA_Games</a> 2005-10-21 22:16 <a href="http://www.blogjava.net/eagames/archive/2005/10/21/16349.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>