﻿<?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-xyz's blog-文章分类-他山之石</title><link>http://www.blogjava.net/xyzroundo/category/28203.html</link><description>执着......坚持......</description><language>zh-cn</language><lastBuildDate>Sat, 01 Mar 2008 19:37:14 GMT</lastBuildDate><pubDate>Sat, 01 Mar 2008 19:37:14 GMT</pubDate><ttl>60</ttl><item><title>eclipse及其插件介绍和下载</title><link>http://www.blogjava.net/xyzroundo/articles/183205.html</link><dc:creator>xyz</dc:creator><author>xyz</author><pubDate>Sat, 01 Mar 2008 17:56:00 GMT</pubDate><guid>http://www.blogjava.net/xyzroundo/articles/183205.html</guid><wfw:comment>http://www.blogjava.net/xyzroundo/comments/183205.html</wfw:comment><comments>http://www.blogjava.net/xyzroundo/articles/183205.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xyzroundo/comments/commentRss/183205.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xyzroundo/services/trackbacks/183205.html</trackback:ping><description><![CDATA[<p>by xyz&nbsp; from papa<br />
<br />
0.Eclipse下载<br />
EMF,GEF - Graphical Editor Framework,UML2,VE - Visual Editor都在这里下载<br />
http://www.eclipse.org/downloads/index.php</p>
<p>A.. properties http://propedit.sourceforge.jp/eclipse/updates/;</p>
<p>A.. jode http://www.technoetic.com/eclipse/update; </p>
<p>A.. Eclipse update site: http://eclipse-tools.sourceforge.net/updates/&nbsp;&nbsp; 查看接口实现类插件 </p>
<p>A.. jsEclipse http://www.interaktonline.com/ JS编辑器</p>
<p>0.5.lomboz J2EE插件,开发JSP,EJB<br />
http://forge.objectweb.org/projects/lomboz<br />
1.MyEclipse J2EE开发插件，支持SERVLET/JSP/EJB/数据库操纵等 <br />
http://www.myeclipseide.com<br />
&nbsp;<br />
2.Properties Editor&nbsp; 编辑java的属性文件，并可以自动存盘为Unicode格式 <br />
http://propedit.sourceforge.jp/index_en.html <br />
&nbsp; <br />
3.Colorer Take&nbsp; 为上百种类型的文件按语法着色 <br />
http://colorer.sourceforge.net/ <br />
&nbsp; <br />
4.XMLBuddy 编辑xml文件<br />
http://www.xmlbuddy.com <br />
&nbsp; <br />
5.Code Folding&nbsp; 加入多种代码折叠功能（比eclipse自带的更多） <br />
http://www.coffee-bytes.com/servlet/PlatformSupport <br />
&nbsp; <br />
6.Easy Explorer&nbsp; 从eclipse中访问选定文件、目录所在的文件夹 <br />
http://easystruts.sourceforge.net/ <br />
&nbsp; <br />
7.Fat Jar 打包插件，可以方便的完成各种打包任务，可以包含外部的包等 <br />
http://fjep.sourceforge.net/ <br />
&nbsp; <br />
8.RegEx Test 测试正则表达式 <br />
http://brosinski.com/stephan/archives/000028.php <br />
&nbsp; <br />
9.JasperAssistant 报表插件（强，要钱的） <br />
http://www.jasperassistant.com/ <br />
&nbsp; <br />
10.Jigloo GUI Builder ＪＡＶＡ的ＧＵＩ编辑插件 <br />
http://cloudgarden.com/jigloo/ <br />
&nbsp; <br />
11.Profiler 性能跟踪、测量工具，能跟踪、测量ＢＳ程序 <br />
http://sourceforge.net/projects/eclipsecolorer/ <br />
&nbsp; <br />
12.AdvanQas 提供对if/else等条件语句的提示和快捷帮助（自动更改结构等） <br />
http://eclipsecolorer.sourceforge.net/advanqas/index.html <br />
&nbsp; <br />
13.Log4E Log4j插件，提供各种和Log4j相关的任务，如为方法、类添加一个logger等 <br />
http://log4e.jayefem.de/index.php/Main_Page <br />
&nbsp; <br />
14.VSSPlugin VSS插件 <br />
http://sourceforge.net/projects/vssplugin <br />
&nbsp; <br />
15.Implementors 提供跳转到一个方法的实现类，而不是接中的功能（实用!） <br />
http://eclipse-tools.sourceforge.net/implementors/ <br />
&nbsp; <br />
16.Call Hierarchy 显示一个方法的调用层次（被哪些方法调，调了哪些方法） <br />
http://eclipse-tools.sourceforge.net/call-hierarchy/index.html <br />
&nbsp; <br />
17.EclipseTidy 检查和格式化HTML/XML文件 <br />
http://eclipsetidy.sourceforge.net/ <br />
&nbsp; <br />
18.Checkclipse 检查代码的风格、写法是否符合规范 <br />
http://www.mvmsoft.de/content/plugins/checkclipse/checkclipse.htm <br />
&nbsp; <br />
19.Hibernate Synchronizer Hibernate插件，自动映射等 <br />
http://www.binamics.com/hibernatesync/ <br />
&nbsp; <br />
20.VeloEclipse&nbsp; Velocity插件 <br />
http://propsorter.sourceforge.net/ <br />
&nbsp; <br />
21.EditorList 方便的列出所有打开的Editor <br />
http://editorlist.sourceforge.net/ <br />
&nbsp; <br />
22.MemoryManager 内存占用率的监视 <br />
http://cloudgarden.com/memorymanager/ <br />
&nbsp;<br />
23.swt-designer java的GUI插件<br />
http://www.swt-designer.com/<br />
&nbsp;<br />
24.TomcatPlugin 支持Tomcat插件 <br />
http://www.sysdeo.com/eclipse/tomcatPlugin.html<br />
&nbsp;<br />
25.XML Viewer <br />
http://tabaquismo.freehosting.net/ignacio/eclipse/xmlview/index.html<br />
&nbsp;<br />
26.quantum 数据库插件<br />
http://quantum.sourceforge.net/<br />
&nbsp;<br />
27.Dbedit 数据库插件<br />
http://sourceforge.net/projects/dbedit<br />
&nbsp;<br />
28.clay.core 可视化的数据库插件 <br />
http://www.azzurri.jp/en/software/index.jsp <br />
http://www.azzurri.jp/eclipse/plugins<br />
&nbsp;<br />
29.hiberclipse hibernate插件 <br />
http://hiberclipse.sourceforge.net<br />
http://www.binamics.com/hibernatesync<br />
&nbsp;<br />
30.struts-console Struts插件<br />
http://www.jamesholmes.com/struts/console/<br />
&nbsp;<br />
31.easystruts Struts插件<br />
http://easystruts.sourceforge.net <br />
&nbsp;<br />
32.veloedit Velocity插件<br />
http://veloedit.sourceforge.net/<br />
&nbsp;<br />
33.jalopy 代码整理插件<br />
http://jalopy.sourceforge.net/<br />
&nbsp;<br />
34.JDepend 包关系分析<br />
http://andrei.gmxhome.de/jdepend4eclipse/links.html<br />
&nbsp;<br />
35.Spring IDE Spring插件<br />
http://springide-eclip.sourceforge.net/updatesite/<br />
&nbsp;<br />
36.doclipse 可以产生xdoclet 的代码提示<br />
http://beust.com/doclipse/</p>
<img src ="http://www.blogjava.net/xyzroundo/aggbug/183205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xyzroundo/" target="_blank">xyz</a> 2008-03-02 01:56 <a href="http://www.blogjava.net/xyzroundo/articles/183205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mail</title><link>http://www.blogjava.net/xyzroundo/articles/168439.html</link><dc:creator>xyz</dc:creator><author>xyz</author><pubDate>Tue, 18 Dec 2007 03:45:00 GMT</pubDate><guid>http://www.blogjava.net/xyzroundo/articles/168439.html</guid><wfw:comment>http://www.blogjava.net/xyzroundo/comments/168439.html</wfw:comment><comments>http://www.blogjava.net/xyzroundo/articles/168439.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xyzroundo/comments/commentRss/168439.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xyzroundo/services/trackbacks/168439.html</trackback:ping><description><![CDATA[package com.royal.mail;<br />
<br />
import java.util.Properties;<br />
<br />
import javax.activation.DataHandler;<br />
import javax.activation.FileDataSource;<br />
import javax.mail.Address;<br />
import javax.mail.BodyPart;<br />
import javax.mail.Message;<br />
import javax.mail.Multipart;<br />
import javax.mail.Session;<br />
import javax.mail.Transport;<br />
import javax.mail.internet.InternetAddress;<br />
import javax.mail.internet.MimeBodyPart;<br />
import javax.mail.internet.MimeMessage;<br />
import javax.mail.internet.MimeMultipart;<br />
<br />
public class Mail<br />
<br />
{<br />
<br />
<br />
&nbsp;&nbsp; &nbsp;private MimeMessage mimeMsg; // MIME邮件对象<br />
&nbsp;&nbsp; &nbsp;private Session session; // 邮件会话对象<br />
&nbsp;&nbsp; &nbsp;private Properties props; // 系统属性<br />
&nbsp;&nbsp; &nbsp;//private boolean needAuth = false; // smtp是否需要认证<br />
&nbsp;&nbsp; &nbsp;private String username = ""; // smtp认证用户名和密码<br />
&nbsp;&nbsp; &nbsp;private String password = "";<br />
&nbsp;&nbsp; &nbsp;private Multipart mp; // Multipart对象,邮件内容,标题,附件等内容均添加到其中后再生成//MimeMessage对象<br />
<br />
&nbsp;&nbsp; &nbsp;public Mail(String smtp)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;setSmtpHost(smtp);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;createMimeMessage();<br />
&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;public void setSmtpHost(String hostName)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("设置系统属性：mail.smtp.host = " + hostName);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (props == null)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;props = System.getProperties(); // 获得系统属性对象<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;props.put("mail.smtp.host", hostName); // 设置SMTP主机<br />
&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;public boolean createMimeMessage()<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("准备获取邮件会话对象！");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;session = Session.getDefaultInstance(props, null); // 获得邮件会话对象<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.err.println("获取邮件会话对象时发生错误！" + e);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("准备创建MIME邮件对象！");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg = new MimeMessage(session); // 创建MIME邮件对象<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mp = new MimeMultipart(); // mp 一个multipart对象<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.err.println("创建MIME邮件对象失败！" + e);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
<br />
&nbsp;&nbsp; &nbsp;public void setNeedAuth(boolean need) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("设置smtp身份认证：mail.smtp.auth = " + need);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (props == null)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;props = System.getProperties();<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (need) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;props.put("mail.smtp.auth", "true");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} else {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;props.put("mail.smtp.auth", "false");<br />
<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;public void setNamePass(String name, String pass)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("程序得到用户名与密码");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;username = name;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;password = pass;<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;public boolean setSubject(String mailSubject) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("设置邮件主题！");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg.setSubject(mailSubject);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.err.println("设置邮件主题发生错误！");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;public boolean setBody(String mailBody)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("设置邮件体格式");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BodyPart bp = new MimeBodyPart();<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bp.setContent("&lt;meta http-equiv=Content-Type content=text/html; charset=UTF-8&gt;"+mailBody,"text/html;charset=UTF-8");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mp.addBodyPart(bp);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.err.println("设置邮件正文时发生错误！" + e);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;public boolean addFileAffix(String filename) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("增加邮件附件：" + filename);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BodyPart bp = new MimeBodyPart();<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;FileDataSource fileds = new FileDataSource(filename);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bp.setDataHandler(new DataHandler(fileds));<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bp.setFileName(fileds.getName());<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mp.addBodyPart(bp);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.err.println("增加邮件附件：" + filename + "发生错误！" + e);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;public boolean setFrom(String from) {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("设置发信人！");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg.setFrom(new InternetAddress(from)); // 设置发信人<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;public boolean setTo(String to)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("设置收信人");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (to == null)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
<br />
&nbsp;&nbsp; &nbsp;public boolean setCopyTo(String copyto)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("发送附件到");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (copyto == null)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try {<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg.setRecipients(Message.RecipientType.CC,(Address[])InternetAddress.parse(copyto));<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;public boolean sendout()<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;try<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg.setContent(mp);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;mimeMsg.saveChanges();<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("正在发送邮件....");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Session mailSession = Session.getInstance(props, null);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Transport transport = mailSession.getTransport("smtp"); // ？？？<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transport.connect((String) props.get("mail.smtp.host"), username,password);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transport.sendMessage(mimeMsg, mimeMsg.getRecipients(Message.RecipientType.TO));<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// transport.send(mimeMsg);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println("发送邮件成功！");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;transport.close();<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;catch (Exception e)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.err.println("邮件发送失败！" + e);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return false;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />
&nbsp;&nbsp; &nbsp;}<br />
<br />
&nbsp;&nbsp; &nbsp;/*public static void main(String[] args)<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String mailbody = "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;hr&gt;&lt;font color=""red""&gt;hello. This is a testing.&lt;/red&gt;&lt;/body&gt;&lt;/html&gt;";<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Mail themail = new Mail("smtp.163.com");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;themail.setNeedAuth(true);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (themail.setSubject("dkjjf") == false)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (themail.setBody(mailbody) == false)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (themail.setTo("lyh@jobbaidu.com") == false)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (themail.setFrom("iversonpa@163.com") == false)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//if (themail.addFileAffix("d://aaa.rar") == false)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//return; // 附件在本地机子上的绝对路径<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;themail.setNamePass("iversonpa", "******"); // 用户名与密码<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (themail.sendout() == false)<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return;<br />
&nbsp;&nbsp; &nbsp;}*/<br />
<br />
}<br />
<br />
<img src ="http://www.blogjava.net/xyzroundo/aggbug/168439.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xyzroundo/" target="_blank">xyz</a> 2007-12-18 11:45 <a href="http://www.blogjava.net/xyzroundo/articles/168439.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts+hibernate+spring 登录开发实例</title><link>http://www.blogjava.net/xyzroundo/articles/168438.html</link><dc:creator>xyz</dc:creator><author>xyz</author><pubDate>Tue, 18 Dec 2007 03:43:00 GMT</pubDate><guid>http://www.blogjava.net/xyzroundo/articles/168438.html</guid><wfw:comment>http://www.blogjava.net/xyzroundo/comments/168438.html</wfw:comment><comments>http://www.blogjava.net/xyzroundo/articles/168438.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xyzroundo/comments/commentRss/168438.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xyzroundo/services/trackbacks/168438.html</trackback:ping><description><![CDATA[<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">说明：此教程是oksonic视频教程的修改，我移植到eclipse3.2+myEclipse5.0环境下。原来放在我在和讯的博客上，写的比较早，完成于去年下半学期，当时还在学校，现在出来打工了，今年7月毕业。感觉在CSDN的高手多，所以转移至此。</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">功能：集合了SSH框架，完成简单的登陆功能</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">工具：<span><br />
&nbsp;&nbsp;&nbsp; eclipse-SDK-3.2.1</span>、MyEclipse_5.0.1GA_E3.2、Tomcat_5.5.15、mysql-5.0.18</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">相关资料下载<span><br />
</span>原来的资料都是放在gbaopan下，现在gbaopan关了，没有地方放了，只能放在邮箱里，在发件箱里的附件中</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;"><br />
</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">视频教程下载邮件主题：&nbsp;struts+hibernate+spring视频<span>.part1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struts+hibernate+spring</span>视频.part2</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">工程下载邮件主题：<span>&nbsp;&nbsp;struts+hibernate+spring_src.part1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;struts+hibernate+spring_src.part1<br />
</span>说明文件邮件主题：&nbsp;&nbsp;struts+hibernate+spring_说明<span><br />
properties2GBK.bat&nbsp;&nbsp;struts+hibernate+spring_</span>说明<span>&nbsp;<br />
&nbsp;<br />
</span>开始。。新建工程：名称为<span> login<br />
&nbsp;<br />
</span>创建Struts框架<span><br />
&nbsp;<br />
</span>创建 index.jsp，增加一链接指向<span> login.jsp<br />
&lt;html&gt;<br />
&nbsp; &lt;head&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;Struts+Spring+Hibernate&lt;/title&gt;<br />
&nbsp; &lt;/head&gt;<br />
&nbsp; <br />
&nbsp; &lt;body&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;a href="login.jsp"&gt;Login&lt;/a&gt;<br />
&nbsp; &lt;/body&gt;<br />
&lt;/html&gt;<br />
&nbsp;<br />
</span>按下Ctrl + N，创建 login.jsp、LoginAction，使用MyEclipse的向导就可以了，记得选对正确的版本<span><br />
&nbsp;<br />
</span>在ActionForm配置页中选择类型为动态Form，并继承于DynaValidatorForm，新增两个属性：username、password，<span><br />
</span>在创建jsp文件打上钩，将路径改为/login.jsp，然后下一步，改LoginAction的Input source改为/login.jsp，点击完成<span><br />
&nbsp;<br />
</span>按下Ctrl + N 创建一个forwards，记得选对正确的版本<span><br />
name </span>输入<span> indexGo<br />
</span>路径选择<span> /index.jsp<br />
&nbsp;<br />
</span>配置<span>validator<br />
</span>先添加Struts插件，使用向导<span><br />
Plugin class : org.apache.struts.validator.ValidatorPlugIn<br />
Property : pathnames<br />
Value : /WEB-INF/validator-rules.xml,/WEB-INF/validation.xml<br />
</span>这里需要两个xml文件<span><br />
</span>现在创建&#8220;validation.xml&#8221; 文件</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;<br />
</span><span style="font-size: 12pt;">文件内容如下：<span><br />
&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br />
&lt;!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
Commons Validator Rules Configuration 1.1.3//EN"
"validator_1_1_3.dtd" &gt;<br />
&lt;form-validation&gt;<br />
&nbsp;&lt;formset&gt;<br />
&nbsp; &lt;form name="loginForm"&gt;<br />
&nbsp;&nbsp; &lt;field property="username"
depends="required"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;arg0 key="prompt.username" /&gt;<br />
&nbsp;&nbsp; &lt;/field&gt;<br />
&nbsp;&nbsp; &lt;field property="password"
depends="required"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;arg0 key="prompt.password" /&gt;<br />
&nbsp;&nbsp; &lt;/field&gt;<br />
&nbsp; &lt;/form&gt;<br />
&nbsp;&lt;/formset&gt;<br />
&lt;/form-validation&gt;<br />
&nbsp;<br />
</span>编辑资源文件<span>&#8220;ApplicationResources.properties&#8221;<br />
</span>增加以下内容<span><br />
&nbsp;<br />
prompt.username=User Name<br />
prompt.password=User Password<br />
errors.required={0} is required.<br />
&nbsp;<br />
</span>再创建中文件资源文件<span>&#8220;ApplicationResources_zh_CN.properties&#8221;<br />
</span>增加以下内容</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">prompt.username=</span><span style="font-size: 12pt;">用户名称<span><br />
prompt.password=</span>登录密码<span><br />
errors.required={0} </span>必需填写！</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">我这没有用Properties Editor插件，所以在tomcat发布后会显示乱码，我们可以用native2ascii来解决<span><br />
</span>我建了个批处理文件<span>properties2GBK.bat<br />
native2ascii -encoding gbk ApplicationResources_zh_CN.properties
temp.properties<br />
del ApplicationResources_zh_CN.properties<br />
rename temp.properties ApplicationResources_zh_CN.properties<br />
</span>放在你的classpath下，或者拷到你要转GBK的地方，双击一下就可以了<span><br />
</span>我刚开始在eclipse编辑中文properties文件,保存后再打开，也会出现乱码，只要在eclipse上设置一下就可以了<span><br />
</span>具体设置：Eclipse--&gt;Preferences...--&gt;在&#8220;type filter text&#8220;栏中输入&#8221;Content Types&#8220;查找，<span><br />
</span>然后在选择右边的Text下边相应的文件后缀名，即properties.修改其编码就可。可以修改成<span>GBK<br />
</span>我这已经改好了，直接打开就是汉语了。。。<span><br />
</span>建议下载 properties Editor插件，我这上不了外国网站，没有办法。。。。有空再下吧。。<span><br />
&nbsp;<br />
</span>修改struts-config.xml文件<span><br />
</span>在以下位置增加<span>validate="true"<br />
&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;<br />
&nbsp; &lt;/action-mappings&gt;<br />
&nbsp;<br />
</span>这里说明提交的数据必需经过验证，而验证则是通过validator框架进行的。</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改web.xml文件<span><br />
</span>增加<span><br />
&nbsp;&lt;welcome-file-list&gt;<br />
&nbsp;&nbsp; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;<br />
&nbsp; &lt;/welcome-file-list&gt;<br />
</span>显示主页<span><br />
&nbsp; <br />
</span>修改LoginAction.java文件的execute方法，内容如下<span><br />
public ActionForward execute(<br />
&nbsp; ActionMapping mapping,<br />
&nbsp; ActionForm form,<br />
&nbsp; HttpServletRequest request,<br />
&nbsp; HttpServletResponse response) {<br />
&nbsp; DynaValidatorForm loginForm = (DynaValidatorForm) form;<br />
&nbsp; String username=loginForm.getString("username");<br />
&nbsp; String password=loginForm.getString("password");<br />
&nbsp;
if(username.equals("test")||password.equals("test")){<br />
&nbsp;&nbsp; return mapping.findForward("indexGo");<br />
&nbsp; }else{<br />
&nbsp;&nbsp; return mapping.getInputForward();<br />
&nbsp; }<br />
&nbsp;}<br />
&nbsp;<br />
</span>现在再修改一下<span>login.jsp<br />
</span>增加以下部份<span><br />
&lt;%@ page language="java" contentType="text/html;
charset=UTF-8" %&gt;<br />
&nbsp;<br />
</span>其中charset=UTF-8 是使用UTF-8的字符编码，这也是为了支持国际化而使用的。要不然中文还是会显示乱码<span><br />
</span>关于乱码解决，网上查资料，一查就有一堆<span><br />
</span>我们现在还没有传递中文参数，要不然还得加个过滤器。。</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;<br />
</span><span style="font-size: 12pt;">好了，现在可以启动Tomcat进行测试了<span><br />
<a href="http://localhost:8080/login/">http://localhost:8080/login/</a> </span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;<br />
</span><span style="font-size: 12pt;">如果不输入任何数据而直接提交表单的话就可以看到效果了。<span><br />
&nbsp;<br />
</span>好了，如果没有什么问题的话就继续往下看吧，如果有问题的话就得往上看了<span>^_^<br />
</span>出现了乱码，我们用native2ascii来解决，非得我重启一下!&gt; ok了<span><br />
&nbsp;<br />
</span>现在创建Spring框架了，在这里我将Spring所有的包全部加载进去，因为我还不知道具体用到哪些类，全部加进去方便点<span><br />
&nbsp;<br />
</span>单选框选第二个，这样的话所有的类库和标签等都将拷贝到项目中去，这样方便以后的布署<span><br />
</span>下一步后是创建配置文件，将文件放到&#8220;WebRoot/WEB-INF&#8221;目录下，文件名称为<span>&#8220;applicationContext.xml&#8221;<br />
&nbsp;<br />
&nbsp;<br />
</span>配置struts-config.xml文件，添加（spring）的插件<span><br />
&nbsp;<br />
&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;<br />
&nbsp;<br />
&nbsp; <br />
</span>修改LoginAction配置<span><br />
&nbsp;<br />
</span>原：<span><br />
&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;<br />
&nbsp;<br />
&nbsp; &lt;/action-mappings&gt;<br />
&nbsp;<br />
</span>改为：<span><br />
&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="org.springframework.web.struts.DelegatingActionProxy" /&gt;<br />
&nbsp; &lt;/action-mappings&gt;<br />
&nbsp;<br />
&nbsp; <br />
</span>这里将使用spring的代理器来对Action进行控制<span><br />
&nbsp;<br />
</span>当提交到/login.do是将控制权交给了spring，然后由spring来决定是否转回到struts的<span>Action<br />
&nbsp;<br />
</span>现在来配置<span>spring<br />
&nbsp;<br />
&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">http://www.springframework.org/dtd/spring-beans.dtd</a>"&gt;<br />
&nbsp;<br />
&lt;beans&gt;<br />
&nbsp;&lt;bean name="/login"
class="com.test.struts.action.LoginAction"
singleton="false"&gt;&lt;/bean&gt;<br />
&lt;/beans&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;<br />
</span><span style="font-size: 12pt;">属性singleton="false"，指明了Action 的实例获取方式为每次重新创建。解决了Struts中令人诟病的线程安全问题（Struts中，由一个Action实例处理所有的请求，这就导致了类公用资源在并发请求中的线程同步问题。）（摘自spring开发指南<span>)<br />
</span>测试一下，如果没有什么问题的话就继续往下看吧，如果有问题的话就得往上看了<span>^_^<br />
</span>好的，struts spring俩人成为朋友了，友好的集成到了一起。。。<span><br />
&nbsp; <br />
</span>建立数据库在 这里我使用的是<span>mysql-5.0.18<br />
</span>配置好mySql连接<span>......<br />
</span>不好意思，这里我忘记驱动怎么写了。。。<span><br />
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; <br />
&nbsp;<br />
</span>添加记录<span> insert into user (USERNAME,PASSWORD) values
('test','test')</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">创建Hibernate框架<span><br />
</span>新建包<span>com.test.hibernate<br />
com.test.beans<br />
</span>选hibernate3.1 libraries全选，我也不知道那个具体有什么用^_^，可能只选第一个也行，但考虑还要用DAO，第三个也选上了，<span><br />
</span>看第二是高级支持，也加上了，没试里面的作用，大家有空可以试一下。。<span><br />
</span>第二步选 spring configuration file 我们直接在Spring配置hibernate的连接。。就不用创建hibernate.cfg.xml了<span><br />
</span>第三步选existing Spring configuration file我们刚才已经创建了一个。。<span><br />
&nbsp;SessionFactory ID</span>就直接填<span>sessionFactory<br />
</span>第四步 Bean Id填 dataSource 我们用JDBC Driver,DB Profile选刚才配置好的</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">使用MyEclipse的数据Database Explorer工具创建User.hmb.xml、AbstractUser.java、User.java，UserDAO文件<span><br />
</span>这里选项比较多，大家看视频。。我就不一一说明了。。。不懂的看书^_^</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">打开User.hbm.xml配置文件，把 catalog="meilvin" 这一项删除了,要不后果很严重。因为mySql在连接的时候要写上数据库<span><br />
</span>如果我们在这里也写上数据库的名字的话就会重复了，就变成了meilvin.meilvin.user,显然是错的。后面就会报错，我深有体会。</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;"><br />
</span><span style="font-size: 12pt;">修改UserDAO,增加如下方法<span><br />
public boolean isValidUser(String username, String password) {<br />
&nbsp; String hql = "from User u where u.username=? and
u.password=?";<br />
&nbsp; String []userInfo=new String[2];<br />
&nbsp; userInfo[0]=username;<br />
&nbsp; userInfo[1]=password;<br />
&nbsp; List userList = this.getHibernateTemplate().find(hql, userInfo);<br />
&nbsp; if (userList.size() &gt; 0) {<br />
&nbsp;&nbsp; return true;<br />
&nbsp; }<br />
&nbsp; return false;<br />
&nbsp;}</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;<br />
</span><span style="font-size: 12pt;">修改LoginAction.java文件，使用userDao的方法来进行用户验证<span><br />
package com.test.struts.action;<br />
&nbsp;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
&nbsp;<br />
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;<br />
&nbsp;<br />
import com.test.UserDAO;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">public
class LoginAction extends Action {</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;private
UserDAO userDAO;<br />
&nbsp;<br />
&nbsp;public UserDAO getUserDAO() {<br />
&nbsp; return userDAO;<br />
&nbsp;}<br />
&nbsp;<br />
&nbsp;public void setUserDAO(UserDAO userDAO) {<br />
&nbsp; this.userDAO = userDAO;<br />
&nbsp;}<br />
&nbsp;<br />
&nbsp;public ActionForward execute(ActionMapping mapping, ActionForm form,<br />
&nbsp;&nbsp; HttpServletRequest request, HttpServletResponse response) {<br />
&nbsp; DynaValidatorForm loginForm = (DynaValidatorForm) form;<br />
&nbsp; // TODO Auto-generated method stub<br />
&nbsp; String username = (String) loginForm.get("username");<br />
&nbsp; String password = (String) loginForm.get("password");<br />
&nbsp; loginForm.set("password", null);<br />
&nbsp; if (userDAO.isValidUser(username,password)) {<br />
&nbsp;&nbsp; return mapping.findForward("indexGo");<br />
&nbsp; } else {<br />
&nbsp;&nbsp; return mapping.getInputForward();<br />
&nbsp; }<br />
&nbsp;}<br />
}<br />
&nbsp;<br />
</span><span style="font-size: 12pt;">现在剩下最后的spring配置了<span><br />
</span>把原来的<span><br />
&lt;bean name="/login"
class="com.test.struts.action.LoginAction"
singleton="false"&gt;&lt;/bean&gt;<br />
</span>删除了<span><br />
</span>在最底下增加<span><br />
&nbsp;&lt;bean name="/login"
class="com.test.struts.action.LoginAction"
singleton="false"&gt;<br />
&nbsp; &lt;property name="userDAO"&gt;<br />
&nbsp;&nbsp; &lt;ref bean="UserDAO" /&gt;<br />
&nbsp; &lt;/property&gt;<br />
&nbsp;&lt;/bean&gt;<br />
</span>利用反转控制产生<span>action<br />
</span>现在可以进行测试了,可以登陆了<span>^-^<br />
</span>老是说log4j没有配置，下次视频配置一下。。。成功了。。</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;"><br />
</span><span style="font-size: 12pt;">注册新用户，用户浏览、删除用户</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">打开<span>
UserDAO.java </span>文件，增加以下方法：<span><br />
&nbsp;public boolean addUser(User user) {<br />
&nbsp; try {<br />
&nbsp;&nbsp; //</span>调用前面save方法<span><br />
&nbsp;&nbsp; save(user);<br />
&nbsp; } catch (Exception e) {<br />
&nbsp;&nbsp; System.out.println(e.getMessage());<br />
&nbsp;&nbsp; return false;<br />
&nbsp; }<br />
&nbsp; return true;<br />
&nbsp;}</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;"><br />
</span><span style="font-size: 12pt;">按下 Ctrl + N ，使用向导创建 adduser.jsp 、AdduserForm(DynaValidatorForm)、AdduserAction.java文件，这是注册新用户的<span>Action<br />
</span>我用的是maxthon浏览器，如果是add.jsp，它会当做广告拦下来，，，，多加个user...</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改配置内容如下：<span><br />
&lt;action<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attribute="adduserForm"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; input="/adduser.jsp"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name="adduserForm"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path="/adduser"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; validate="true"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
type="org.springframework.web.struts.DelegatingActionProxy" /&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">第一句实现了必须对提交的数据进行验证<span><br />
</span>第二句实现了和spring集成</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
AdduserAction.java </span>文件，内容如下：</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;private
UserDAO userDAO;<br />
&nbsp;<br />
&nbsp;public UserDAO getUserDAO() {<br />
&nbsp; return userDAO;<br />
&nbsp;}<br />
&nbsp;public void setUserDAO(UserDAO userDAO) {<br />
&nbsp; this.userDAO = userDAO;<br />
&nbsp;}</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;public
ActionForward execute(<br />
&nbsp; ActionMapping mapping,<br />
&nbsp; ActionForm form,<br />
&nbsp; HttpServletRequest request,<br />
&nbsp; HttpServletResponse response) {<br />
&nbsp; DynaValidatorForm adduserForm = (DynaValidatorForm) form;<br />
&nbsp; User user = new User();<br />
&nbsp; user.setUsername(adduserForm.getString("username"));<br />
&nbsp; user.setPassword(adduserForm.getString("password"));<br />
&nbsp; adduserForm.set("password", null);<br />
&nbsp; if (userDAO.addUser(user)) {<br />
&nbsp;&nbsp; return mapping.findForward("indexGo");<br />
&nbsp; } else {<br />
&nbsp;&nbsp; return mapping.getInputForward();<br />
&nbsp; }<br />
&nbsp;}</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">关于在Action中使用 User 对像，我在这里没有使用 IoC 方式进行管理，这不好，希望大家在正式应用中使用。</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">在spring配置文件（applicationContext.xml）中加入以下内容：<span><br />
&nbsp;&lt;bean name="/adduser"
class="com.test.struts.action.AdduserAction"<br />
&nbsp; singleton="false"&gt;<br />
&nbsp; &lt;property name="userDAO"&gt;<br />
&nbsp;&nbsp; &lt;ref bean="UserDAO" /&gt;<br />
&nbsp; &lt;/property&gt;<br />
&nbsp;&lt;/bean&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
index.jsp </span>文件<span><br />
&lt;html&gt;<br />
&nbsp; &lt;head&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;Struts+Spring+Hibernate&lt;/title&gt;<br />
&nbsp; &lt;/head&gt;<br />
&nbsp; <br />
&nbsp; &lt;body&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;a href="login.jsp"&gt;Login&lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;br&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;a href="add.jsp"&gt;Add User&lt;/a&gt;<br />
&nbsp; &lt;/body&gt;<br />
&lt;/html&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
adduser.jsp </span>文件的首行，替换为以下内容，目的是为了使用UTF-8的编码格式显示页面<span><br />
&lt;%@ page language="java" contentType="text/html;
charset=UTF-8" %&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
validation.xml </span>文件，加入以下内容：<span><br />
&nbsp; &lt;form name="adduserForm"&gt;<br />
&nbsp;&nbsp; &lt;field property="username"
depends="required"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;arg0 key="prompt.username" /&gt;<br />
&nbsp;&nbsp; &lt;/field&gt;<br />
&nbsp;&nbsp; &lt;field property="password"
depends="required"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;arg0 key="prompt.password" /&gt;<br />
&nbsp;&nbsp; &lt;/field&gt;<br />
&nbsp; &lt;/form&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;"><br />
</span><span style="font-size: 12pt;">现在整个 AddUser 已经完成，如果你觉得不放心的话可以在这里停一停先进行这一段的测试！</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">创建一个Action用于查询数据，名称为 find</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">创建<span>
display.jsp </span>文件，用于显示所有用户</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">创建一个 forward displayGO 指向 display.jsp 选中 redirect</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
UserDAO.java </span>文件，增加 findAllUser() 方法，代码如下：<span><br />
&nbsp;public List findAllUser() {<br />
&nbsp; List users=this.getHibernateTemplate().find("from User u");<br />
&nbsp; if(users.size()&gt;0)<br />
&nbsp;&nbsp; return users;<br />
&nbsp; return null;<br />
&nbsp;}</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
struts-config.xml </span>文件<span><br />
&lt;action path="/find"
type="org.springframework.web.struts.DelegatingActionProxy" /&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
FindAction.java </span>文件，内容如下：<span><br />
&nbsp;private UserDAO userDAO;<br />
&nbsp;<br />
&nbsp;public UserDAO getUserDAO() {<br />
&nbsp; return userDAO;<br />
&nbsp;}<br />
&nbsp;public void setUserDAO(UserDAO userDAO) {<br />
&nbsp; this.userDAO = userDAO;<br />
&nbsp;}</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;public
ActionForward execute(<br />
&nbsp; ActionMapping mapping,<br />
&nbsp; ActionForm form,<br />
&nbsp; HttpServletRequest request,<br />
&nbsp; HttpServletResponse response) {<br />
&nbsp; List users=userDAO.findAllUser();<br />
&nbsp; if(users!=null){<br />
&nbsp;&nbsp; HttpSession session=request.getSession();<br />
&nbsp;&nbsp; session.setAttribute("users",users);<br />
&nbsp;&nbsp; return mapping.findForward("displayGo");<br />
&nbsp; }<br />
&nbsp; return mapping.getInputForward();<br />
&nbsp;}</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">在spring配置文件（applicationContext.xml）中加入以下内容：<span><br />
&nbsp;&lt;bean name="/find"
class="com.test.struts.action.FindAction"
singleton="false"&gt;<br />
&nbsp; &lt;property name="userDAO"&gt;<br />
&nbsp;&nbsp; &lt;ref bean="UserDAO" /&gt;<br />
&nbsp; &lt;/property&gt;<br />
&nbsp;&lt;/bean&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
display.jsp </span>文件，内容如下：<span><br />
&lt;%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%&gt;<br />
&lt;%@ taglib uri="<a href="http://jakarta.apache.org/struts/tags-bean">http://jakarta.apache.org/struts/tags-bean</a>"
prefix="bean"%&gt; <br />
&lt;%@ taglib uri="<a href="http://jakarta.apache.org/struts/tags-html">http://jakarta.apache.org/struts/tags-html</a>"
prefix="html"%&gt;<br />
&lt;%@ taglib uri="<a href="http://jakarta.apache.org/struts/tags-logic">http://jakarta.apache.org/struts/tags-logic</a>"
prefix="logic"%&gt;<br />
&lt;html&gt;<br />
&nbsp; &lt;head&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;DISPLAY&lt;/title&gt;<br />
&nbsp; &lt;/head&gt;<br />
&nbsp; &lt;body&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;logic:present name="users"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;form action="del.do"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;table border="1"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;logic:iterate id="element"
name="users"&gt;<br />
&nbsp;&lt;tr&gt;&lt;td width="100"&gt;<br />
&nbsp; &lt;input type="radio" name="select"
value="&lt;bean:write name="element"
property="id"/&gt;"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &lt;bean:write name="element" property="username"/&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/td&gt;&lt;/tr&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/logic:iterate&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/table&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;INPUT type="submit" name="Submit"
value="submit"&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/form&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/logic:present&gt;<br />
&nbsp; &lt;/body&gt;<br />
&lt;/html&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">现在整个 Display 已经完成，如果你觉得不放心的话可以在这里停一停先进行这一段的测试！</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">新建一个 Action 用于删除选中的用户，name：del</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
struts-config.xml </span>文件中的以下内容为：<span><br />
&lt;action path="/del"
type="org.springframework.web.struts.DelegatingActionProxy" /&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
UserDAO.java </span>文件，增加以下方法<span><br />
&nbsp;public boolean delUser(Integer lid) {<br />
&nbsp; try {<br />
&nbsp;&nbsp; User user=(User)findById(lid);<br />
&nbsp;&nbsp; this.getHibernateTemplate().delete(user);<br />
&nbsp; } catch (Exception e) {<br />
&nbsp;&nbsp; System.out.println(e.getMessage());<br />
&nbsp;&nbsp; return false;<br />
&nbsp; }<br />
&nbsp; return true;<br />
&nbsp;}</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
DelAction.java </span>文件，内容如下：<span><br />
public class DelAction extends Action {</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;private
UserDAO userDAO;</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;public
UserDAO getUserDAO() {<br />
&nbsp; return userDAO;<br />
&nbsp;}</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;public
void setUserDAO(UserDAO userDAO) {<br />
&nbsp; this.userDAO = userDAO;<br />
&nbsp;}</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">&nbsp;public
ActionForward execute(<br />
&nbsp; ActionMapping mapping,<br />
&nbsp; ActionForm form,<br />
&nbsp; HttpServletRequest request,<br />
&nbsp; HttpServletResponse response) {<br />
&nbsp; Integer selid=Integer.valueOf(request.getParameter("select"));<br />
&nbsp; if(userDAO.delUser(selid))<br />
&nbsp;&nbsp; return mapping.findForward("indexGo");<br />
&nbsp; return mapping.getInputForward();<br />
&nbsp;}<br />
}<br />
Ctrl+Shift+o</span><span style="font-size: 12pt;">导入包<span><br />
</span>在spring配置文件（applicationContext.xml）中加入以下内容：<span><br />
&nbsp;&lt;bean name="/del"
class="com.test.struts.action.DelAction" singleton="false"&gt;<br />
&nbsp; &lt;property name="userDAO"&gt;<br />
&nbsp;&nbsp; &lt;ref bean="UserDAO" /&gt;<br />
&nbsp; &lt;/property&gt;<br />
&nbsp;&lt;/bean&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">修改<span>
index.jsp </span>文件<span><br />
&lt;html&gt;<br />
&nbsp; &lt;head&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;Struts+Spring+Hibernate&lt;/title&gt;<br />
&nbsp; &lt;/head&gt;<br />
&nbsp; <br />
&nbsp; &lt;body&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;a href="login.jsp"&gt;Login&lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;br&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;a href="add.jsp"&gt;Add User&lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;br&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;a href="find.do"&gt;Display&lt;/a&gt;<br />
&nbsp; &lt;/body&gt;<br />
&lt;/html&gt;</span></span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;"><br />
</span><span style="font-size: 12pt;">代码已经全部完成，可以进行测试了！！！</span></p>
<p style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><span style="font-size: 12pt;">如果测试不成功，请往回查看。。。。完了<span>!!!<br />
</span>失误失误，大小写不注意，就是这种后果，大家以后要注意点哦<span><br />
</span>好了，成功了，祝大家都成功<span>!<br />
</span>拜拜<span>!<br />
</span></span></p>
<img src ="http://www.blogjava.net/xyzroundo/aggbug/168438.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xyzroundo/" target="_blank">xyz</a> 2007-12-18 11:43 <a href="http://www.blogjava.net/xyzroundo/articles/168438.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ajax应用(jsp例子)</title><link>http://www.blogjava.net/xyzroundo/articles/168434.html</link><dc:creator>xyz</dc:creator><author>xyz</author><pubDate>Tue, 18 Dec 2007 03:33:00 GMT</pubDate><guid>http://www.blogjava.net/xyzroundo/articles/168434.html</guid><wfw:comment>http://www.blogjava.net/xyzroundo/comments/168434.html</wfw:comment><comments>http://www.blogjava.net/xyzroundo/articles/168434.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xyzroundo/comments/commentRss/168434.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xyzroundo/services/trackbacks/168434.html</trackback:ping><description><![CDATA[Ajax应用(jsp例子)<br />
<br />
--------------------------------------------------------------------------------<br />
<br />
&nbsp; <br />
<br />
首先是jsp页面和脚本，为了方便写在一个里面<br />
<br />
这是一个很常见的检测用户名是否存在的功能<br />
<br />
这里用的是struts<br />
<br />
&lt;%@ page contentType="text/html; charset=GBK" %&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;<br />
ajax<br />
&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body bgcolor="#ffffff"&gt;<br />
&lt;h1&gt;<br />
&lt;input name="username" type="text" maxlength="20" /&gt;<br />
&lt;input id="chk-name-btn" type="button" value="检测帐号" onclick="testName('&lt;%=request.getContextPath()%&gt;')" /&gt;<br />
&lt;div id="view_name"&gt;&lt;/div&gt;<br />
&lt;/h1&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;script language="javascript"&gt;<br />
&nbsp; if (window.ActiveXObject &amp;&amp; !window.XMLHttpRequest) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.XMLHttpRequest=function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');<br />
&nbsp;&nbsp; };<br />
&nbsp; }//取得XMLHttpRequest对象<br />
<br />
function testName(path){<br />
<br />
//path是取得系统路径<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var view_name=document.getElementById("view_name");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var req=new XMLHttpRequest();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.onreadystatechange=function() {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.readyState==4 &amp;&amp; req.status==200) {//判断状态，4是已发送，200已完成<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(req.responseText==0){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view_name.style.color='green';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view_name.innerHTML='该用户名可以正常使用';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else if(req.responseText==1){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view_name.style.color='red';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view_name.innerHTML='该用户名已经被使用';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view_name.style.color='red';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view_name.innerHTML='该用户名含有非法字符！';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.open('POST', path+'/ajax.do');//struts<br />
<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//req.open('POST', path+'/ajax.servlet');//servlet<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //req.open('POST', path+'/ajax.action');//webwork<br />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.send("");//发送参数如果有参数req.send("username="+user_name);用request取得<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
}<br />
&lt;/script&gt;<br />
<br />
这个jsp页面并没有取得用户名，就是演示一下。还有&lt;div&gt;可以换span，具体作用问美工吧。<br />
<br />
接受ajax请求的action。<br />
<br />
import org.apache.struts.action.*;<br />
import javax.servlet.http.*;<br />
import javax.servlet.http.HttpServlet;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
import java.io.PrintWriter;<br />
<br />
/**<br />
&nbsp;* &lt;p&gt;Title:AjaxAction &lt;/p&gt;<br />
&nbsp;*/<br />
<br />
public class AjaxAction extends Action {<br />
&nbsp; public ActionForward execute(ActionMapping mapping,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActionForm form,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest request,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletResponse response)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws Exception {<br />
&nbsp;&nbsp;&nbsp; PrintWriter out = response.getWriter();<br />
&nbsp;&nbsp;&nbsp; out.print(1);//ajax取得都是字符的输出。如果数据量大的话，还可以用xml来发送和接受<br />
&nbsp;&nbsp;&nbsp; return null;<br />
&nbsp; }<br />
}<br />
<br />
struts-config.xml<br />
<br />
&nbsp;&nbsp;&nbsp; &lt;action type="test.whw.upload.AjaxAction" validate="false" scope="request"&nbsp; path="/ajax"/&gt;<br />
－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br />
<br />
如果是servlet<br />
<br />
web.xml<br />
<br />
&nbsp;&lt;servlet&gt;<br />
&nbsp; &lt;servlet-name&gt;AjaxServlet &lt;/servlet-name&gt;<br />
&nbsp; &lt;servlet-class&gt;servlet.AjaxServlet &lt;/servlet-class&gt;<br />
&nbsp;&lt;/servlet&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;servlet-mapping&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;AjaxServlet &lt;/servlet-name&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;/AjaxServlet .servlet&lt;/url-pattern&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/servlet-mapping&gt;<br />
<br />
AjaxServlet.java<br />
<br />
import java.io.IOException;<br />
import java.io.PrintWriter;<br />
import javax.servlet.ServletException;<br />
import javax.servlet.http.HttpServlet;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
<br />
<br />
<br />
public class AjaxServlet extends HttpServlet {<br />
&nbsp;Logger log = Logger.getLogger(this.getClass());<br />
&nbsp;public void doGet(HttpServletRequest request, HttpServletResponse response)<br />
&nbsp;&nbsp; throws ServletException,IOException {<br />
&nbsp; response.setContentType("text/xml; charset=GBK");<br />
&nbsp; PrintWriter out = response.getWriter();<br />
&nbsp;&nbsp;&nbsp; out.print(2);<br />
&nbsp;&nbsp; }<br />
&nbsp;}<br />
&nbsp;//Process the HTTP Post request<br />
&nbsp;public void doPost(HttpServletRequest request, HttpServletResponse response)<br />
&nbsp;&nbsp; throws ServletException, IOException {<br />
&nbsp; doGet(request, response);<br />
&nbsp;}<br />
<br />
&nbsp;//Process the HTTP Put request<br />
&nbsp;public void doPut(HttpServletRequest request, HttpServletResponse response)<br />
&nbsp;&nbsp; throws ServletException, IOException {<br />
&nbsp;}<br />
<br />
&nbsp;//Process the HTTP Delete request<br />
&nbsp;public void doDelete(HttpServletRequest request,<br />
&nbsp;&nbsp; HttpServletResponse response) throws ServletException, IOException {<br />
&nbsp;}<br />
<br />
&nbsp;//Clean up resources<br />
&nbsp;public void destroy() {<br />
&nbsp;}<br />
}<br />
<br />
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br />
<br />
如果是webwork<br />
<br />
xwork.xml<br />
<br />
&nbsp;&nbsp; &lt;action name="ajax" class="com.whw.upload.action.webwork.AjaxAction" method="ajax"/&gt;<br />
<br />
<br />
AjaxAction.java<br />
<br />
import java.io.PrintWriter;<br />
<br />
public class AjexAlbumAction extends ActionSupport implements Action{<br />
<br />
&nbsp; public void ajax()throws IOException {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PrintWriter pw = ServletActionContext.getResponse().getWriter();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServletActionContext.getResponse().setContentType("text/html;charset=GBK");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pw.print(1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pw.close();<br />
&nbsp; }<br />
<br />
<br />
}<br />
<br />
本例子在winXPsp2、JB9、Eclipse3，j2sdk1.4.1 、Tomcat5、Tomcat4.1都能运行
<img src ="http://www.blogjava.net/xyzroundo/aggbug/168434.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xyzroundo/" target="_blank">xyz</a> 2007-12-18 11:33 <a href="http://www.blogjava.net/xyzroundo/articles/168434.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>log4j步骤</title><link>http://www.blogjava.net/xyzroundo/articles/168432.html</link><dc:creator>xyz</dc:creator><author>xyz</author><pubDate>Tue, 18 Dec 2007 03:31:00 GMT</pubDate><guid>http://www.blogjava.net/xyzroundo/articles/168432.html</guid><wfw:comment>http://www.blogjava.net/xyzroundo/comments/168432.html</wfw:comment><comments>http://www.blogjava.net/xyzroundo/articles/168432.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/xyzroundo/comments/commentRss/168432.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/xyzroundo/services/trackbacks/168432.html</trackback:ping><description><![CDATA[<p><span style="font-family: 宋体;">第一步，</span></p>
<p>Properties<span style="font-family: 宋体;">文件</span>(first_log4j.properties) <span style="font-family: 宋体;">放在系统的</span>src<span style="font-family: 宋体;">包中。（</span>eclipse<span style="font-family: 宋体;">布置在</span>"WEB-INF"classes<span style="font-family: 宋体;">）</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.rootLogger</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">INFO,stdout,logfile</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.category.com.sumit</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">DEBUG</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.stdout</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">org.apache.log4j.ConsoleAppender</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.stdout.layout</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">org.apache.log4j.PatternLayout</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.stdout.layout.ConversionPattern</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;"> [%p][%c]- %m [%d]
%n</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;"># logfile set up.</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.logfile</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">org.apache.log4j.RollingFileAppender</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.logfile.File</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">set up in web.xml</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.logfile.MaxFileSize</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">50MB</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;"># Keep three backup files.</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.logfile.MaxBackupIndex</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">10</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;"># Pattern to output: date
priority [category] - message</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.logfile.layout</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">org.apache.log4j.PatternLayout</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">#log4j.appender.logfile.layout=org.apache.log4j.HTMLLayout</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">#log4j.appender.logfile.layout.ConversionPattern=</span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">时间</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%d%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">优先级</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%p%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">源文件</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%F%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">类</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%c%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">方法</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%M%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">行数</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">%L%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">最全</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%l%n </span><span style="font-size: 10pt; font-family: 宋体; color: #00b400;">信息</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #00b400;">:%m%n------------------------------------------------%n%n</span></p>
<p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: navy;">log4j.appender.logfile.layout.ConversionPattern</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: green;">=</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">%n- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - -
- - - - - -- - - - - - - - - - - - - - - - - - - - %n</span><span style="font-size: 10pt; font-family: 宋体; color: maroon;">时间</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">:%d%n </span><span style="font-size: 10pt; font-family: 宋体; color: maroon;">优先级</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">:%p%n </span><span style="font-size: 10pt; font-family: 宋体; color: maroon;">位置</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">:%l%n </span><span style="font-size: 10pt; font-family: 宋体; color: maroon;">信息</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: maroon;">:%m%n%n</span></p>
<p><span style="font-family: 宋体;">第二步，</span>servlet</p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">package</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> com.royal.listener;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> java.io.FileInputStream;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> java.io.IOException;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> java.util.Properties;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> javax.servlet.ServletConfig;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> javax.servlet.ServletException;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> javax.servlet.http.HttpServlet;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> org.apache.log4j.Logger;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">import</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> org.apache.log4j.PropertyConfigurator;</span></p>
<p style="text-align: left;" align="left"><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">public</span></strong><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">class</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> LogListener </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">extends</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> HttpServlet {</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">private</span></strong><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">static</span></strong><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">final</span></strong><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">long</span></strong><em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000c0;">serialVersionUID</span></em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> = 1L;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">static</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> Logger </span><em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000c0;">log</span></em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> = Logger.<em>getLogger</em>(LogListener.</span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">class</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">public</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> LogListener() {</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; }</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">public</span></strong><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">void</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> init(ServletConfig config) </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">throws</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> ServletException {</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String prefix =
config.getServletContext().getRealPath(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"/"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String properties =
config.getInitParameter(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"log4j_properties"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String logger=config.getInitParameter(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"log4j_outPutFile"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span>String propertiesPath = prefix + properties;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Properties props = </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">new</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> Properties();</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">try</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> {</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileInputStream istream = </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">new</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">
FileInputStream(propertiesPath);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; props.load(istream);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; istream.close();</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//toPrint(props.getProperty("log4j.appender.file.File"));</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String logFile = prefix + logger;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">设置路径</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logFile=logFile.replace(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">'""'</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">, </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">'/'</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; props.setProperty(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"log4j.appender.logfile.File"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">,logFile);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PropertyConfigurator.<em>configure</em>(props);</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">//</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">装入</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f5f;">log4j</span><span style="font-size: 10pt; font-family: 宋体; color: #3f7f5f;">配置信息</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000c0;">log</span></em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">.info(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"</span><span style="font-size: 10pt; font-family: 宋体; color: #2a00ff;">皇家金典项目启动</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">------"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000c0;">log</span></em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">.info(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"LOG</span><span style="font-size: 10pt; font-family: 宋体; color: #2a00ff;">被加载</span><span style="font-size: 10pt; font-family: 宋体; color: #2a00ff;">日志文件位置：</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">+props.getProperty(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"log4j.appender.logfile.File"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">));</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">catch</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;"> (IOException ioe) {</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000c0;">log</span></em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">.error(ioe);</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ioe.printStackTrace();</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #7f0055;">return</span></strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp; }</span></p>
<p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">}</span></p>
<p>Web.xml: (load-on-srartup=1 <span style="font-family: 宋体;">项目启动时加载</span>)</p>
<p><span style="font-family: 宋体;">参数中有一个是</span>logs"log.log<span style="font-family: 宋体;">，自动生成日志文件，生成在项目下面的</span>logs directory<span style="font-family: 宋体;">中，文件名为</span>log.log</p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">servlet</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">servlet-name</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">LogListener</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">servlet-name</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">servlet-class</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">com.royal.listener.LogListener</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">servlet-class</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">init-param</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-name</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">log4j_properties</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-name</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-value</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">WEB-INF/classes/first_log4j.properties</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-value</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">init-param</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">init-param</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-name</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">log4j_outPutFile</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-name</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-value</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">logs"log.log</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">param-value</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">init-param</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p style="text-align: left;" align="left"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">load-on-startup</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">1</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">load-on-startup</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #3f7f7f;">servlet</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: teal;">&gt;</span></p>
<p><span style="font-family: 宋体;">第三步</span>&nbsp;<span style="font-family: 宋体;">使用</span></p>
<p><span style="font-family: 宋体;">如果是普通的</span>JAVA<span style="font-family: 宋体;">类，</span></p>
<p><span style="font-family: 宋体;">就得初始化</span>log<span style="font-family: 宋体;">变量</span></p>
<p><span>static Logger log =
Logger.getLogger(Mail.class);</span></p>
<p><span style="font-family: 宋体;">在要记录日去的地方</span></p>
<p><em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #0000c0;">log</span></em><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">.error(ex+</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"&nbsp;</span><span style="font-size: 10pt; font-family: 宋体; color: #2a00ff;">创建</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">MIME</span><span style="font-size: 10pt; font-family: 宋体; color: #2a00ff;">邮件对象失败！</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #2a00ff;">"</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">); //ex</span><span style="font-size: 10pt; font-family: 宋体; color: black;">是</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">Exception</span><span style="font-size: 10pt; font-family: 宋体; color: black;">对象</span></p>
<p><span style="font-size: 10pt; font-family: 宋体; color: black;">或者</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">
log.info/log.debug/log.warn</span><span style="font-size: 10pt; font-family: 宋体; color: black;">等</span></p>
<p><span style="font-size: 10pt; font-family: 宋体; color: black;">如果是</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">struts</span><span style="font-size: 10pt; font-family: 宋体; color: black;">中的</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">DispatchAction</span><span style="font-size: 10pt; font-family: 宋体; color: black;">的子类，或其它有</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">Log</span><span style="font-size: 10pt; font-family: 宋体; color: black;">的类的子类。</span></p>
<p><span style="font-size: 10pt; font-family: 宋体; color: black;">就可以不用初始化</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: black;">log</span><span style="font-size: 10pt; font-family: 宋体; color: black;">变量。</span></p>
<img src ="http://www.blogjava.net/xyzroundo/aggbug/168432.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/xyzroundo/" target="_blank">xyz</a> 2007-12-18 11:31 <a href="http://www.blogjava.net/xyzroundo/articles/168432.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>