??xml version="1.0" encoding="utf-8" standalone="yes"?>棒球比分直播日本:BlogJava-紫蝶∏飛揚↗-文章分类 - 棒球比分大小怎么算|վ//www.355548.live/algz/category/43410.htmlPurple Butterfly Flying QQ?7101519 Flex,Ext,Spring,Hibernate,EOS,SpringSecurity,Struts //algz.googlecode.com/svn/trunk/zh-cnSat, 18 Jun 2011 03:08:01 GMTSat, 18 Jun 2011 03:08:01 GMT60在spring的bean中获取ServletContext ?servletConfig - 棒球比分大小怎么算|վ//www.355548.live/algz/articles/352560.html紫蝶∏飛揚↗紫蝶∏飛揚↗Sat, 18 Jun 2011 01:44:00 GMT//www.355548.live/algz/articles/352560.html//www.355548.live/algz/comments/352560.html//www.355548.live/algz/articles/352560.html#Feedback0//www.355548.live/algz/comments/commentRss/352560.html//www.355548.live/algz/services/trackbacks/352560.html
在spring的bean中获取ServletContext ?nbsp;servletConfig
  常规方式下获取servletContext需要承HttpServletc,然后获取servletConfigQ通过q个获取servletContextQservletConfig.getServletContext()Q?/div>
  但是spring的bean都是pojoQ和我们常规的操作有些不同?/div>
springl我们提供了两个接口Qorg.springframework.web.context.ServletContextAware和org.springframework.web.context.ServletConfigAware。我们可以让我们的bean实现上边的Q何一个接口就能获取到servletContext?.
代码如下Q?/div>
public class DicBean implements ServletContextAware{
    
private ServletContext servletContext;

public void setServletContext(ServletContext sc) {
    
this.servletContext=sc;
    System.out.println(
"目应用的绝对\径ؓQ?/span>"+servletContext.getRealPath("/"));
}
}


]]>DOM4J 知识详解 - 棒球比分大小怎么算|վ//www.355548.live/algz/articles/338767.html紫蝶∏飛揚↗紫蝶∏飛揚↗Tue, 23 Nov 2010 03:35:00 GMT//www.355548.live/algz/articles/338767.html//www.355548.live/algz/comments/338767.html//www.355548.live/algz/articles/338767.html#Feedback0//www.355548.live/algz/comments/commentRss/338767.html//www.355548.live/algz/services/trackbacks/338767.html一.Document对象,三种创徏Ҏ

1.dXML文g,获得document对象.
            SAXReader reader = new SAXReader();
            Document  document = reader.read(new File("input.xml"));

2.解析XML格式的字W串,获得document对象.
            String text = "<members></members>";
            Document document = DocumentHelper.parseText(text);
3.创徏documentI对?/span>.
            Document document = DocumentHelper.createDocument();
            Element  root = document.addElement("members");// 创徏根节?只有IDOCUMENT对象才能创徏ROOTl点


?节点控制

1.获取文?span style="color: #99cc00">根节?/span>.
           Element   root = document.getRootElement();
2.取得节点的文?br />            String text=memberElm.getText();
也可以用Q?br />            String text=root.elementText("name");   //q个是取得根节点下的name字节点的文字;可以cLM节点下的文本
3.讄节点文字.
           ageElm.setText("29");
4.父节点下获得单个子节点对?/span>.
           Element memberElm=root.element("member");  // "member"是节点名

5.取得父节点下遍历名ؓ"member"的所有子节点.
           List nodes = rootElm.elements("member");
           for (Iterator it = nodes.iterator(); it.hasNext();) {
                 Element elm = (Element) it.next();
                 // do something
            }
6.父节点下?span style="color: #99cc00">遍历所有子节点q行.
            for(Iterator it=root.elementIterator();it.hasNext();){
                Element element = (Element) it.next();
                // do something
            }
7.父节点下d子节?/span>.
           Element ageElm = newMemberElm.addElement("age");

8.父节点下删除子节?/span>.
           parentElm.remove(childElm);// childElm是待删除的节?parentElm是其父节?br />
?属性相?
1.取得某节点下的某属?br />             Element root=document.getRootElement();   
            Attribute attribute=root.attribute("size");// 属性名name
2.取得属性的文字
            String text=attribute.getText();
也可以用:
String text2=root.element("name").attributeValue("firstname");q个是取得根节点下name字节点的属性firstname的?

3.遍历某节点的所有属?br />             Element root=document.getRootElement();   
            for(Iterator it=root.attributeIterator();it.hasNext();){
                Attribute attribute = (Attribute) it.next();
                String text=attribute.getText();
                System.out.println(text);
            }
4.讄某节点的属性和文字.
newMemberElm.addAttribute("name", "sitinspring");
5.讄属性的文字
            Attribute attribute=root.attribute("name");
            attribute.setText("sitinspring");
6.删除某属?br />             Attribute attribute=root.attribute("size");// 属性名name
            root.remove(attribute);
?文?写入XML文g.
1.文中全?不设|编?直接写入的Ş?
XMLWriter writer = new XMLWriter(new FileWriter("output.xml"));
writer.write(document);
writer.close();
2.文中含有中?讄~码格式写入的Ş?
            OutputFormat format = OutputFormat.createPrettyPrint();
            format.setEncoding("GBK");    // 指定XML~码       
            XMLWriter writer = new XMLWriter(new FileWriter("output.xml"),format);
           
            writer.write(document);
            writer.close();
?字符串与XML的{?br /> 1.字W串转化为XML
String text = "<members> <member>sitinspring</member> </members>";
Document document = DocumentHelper.parseText(text);
2.文?或节点的XML转化为字W串.
            SAXReader reader = new SAXReader();
            Document  document = reader.read(new File("input.xml"));           
            Element root=document.getRootElement();               
            String docXmlText=document.asXML();
            String rootXmlText=root.asXML();
            Element memberElm=root.element("member");
            String memberXmlText=memberElm.asXML();
?使用XPath快速找到节?
d的XML文CZ
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
  <name>MemberManagement</name>
  <comment></comment>
  <projects>
    <project>PRJ1</project>
    <project>PRJ2</project>
    <project>PRJ3</project>
    <project>PRJ4</project>
  </projects>
  <buildSpec>
    <buildCommand>
      <name>org.eclipse.jdt.core.javabuilder</name>
      <arguments>
      </arguments>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
</projectDescription>

使用XPath快速找到节点project.
 public static void main(String[] args){
    SAXReader reader = new SAXReader();
   
    try{
      Document  doc = reader.read(new File("sample.xml"));
     
      List projects=doc.selectNodes("/projectDescription/projects/project");
     //Element nodes0=xmlDoc.selectSingleNode("/bookstore"); //采用相对路径,卛_前结?包括当前l点)开始查?与下列结果相?
     //Element nodes=nodes0.selectNodes("book");      ////采用l对路径,卛_前结?包括当前l点)开始查?
     //XPATH语法详见: //www.w3school.com.cn/xpath/xpath_syntax.asp


      Iterator it=projects.iterator();
     
      while(it.hasNext()){
        Element elm=(Element)it.next();      
        System.out.println(elm.getText());
      }
     
    }
    catch(Exception ex){
       ex.printStackTrace();
    }
  }



]]>
JS函数 验证日期合法(试通过) - 棒球比分大小怎么算|վ//www.355548.live/algz/articles/335682.html紫蝶∏飛揚↗紫蝶∏飛揚↗Wed, 20 Oct 2010 05:38:00 GMT//www.355548.live/algz/articles/335682.html//www.355548.live/algz/comments/335682.html//www.355548.live/algz/articles/335682.html#Feedback0//www.355548.live/algz/comments/commentRss/335682.html//www.355548.live/algz/services/trackbacks/335682.html<script type="text/javascript">
 alert("2008-05-11是日期吗?{?"+isDateFormat("2008-05-11"));

 function isDateFormat(txt){ //是否为合法的日期格式:YYYY-MM-DD
if(txt==null || txt == ""){return false;}
else{
   var regex = /[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2}/;   //可按具体格式修改
   if( regex.test(txt) ){
    var noArr = txt.split("-");
    var year = eval(noArr[0]);
    var month = eval(noArr[1]);
    var day = eval(noArr[2]);
    if ( year < 1 || month < 1 || month > 12 || day < 1 || day > 31) {return false;}
    if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30){return false;}
    if (month == 2){
     if ((year % 4 != 0) && day > 29) { return false;}
     if (year % 4 == 0){
      if(year % 100 == 0 && year % 400 != 0 && day > 29){return false;}
      else if (day > 28){ return false;}
     }
    }
    return true;
   }else{return false;}
}
}

 
</script>



]]>
EOS 解决STRUTS标签不能嵌套的问?/title><link>//www.355548.live/algz/articles/333235.html</link><dc:creator>紫蝶∏飛揚↗</dc:creator><author>紫蝶∏飛揚↗</author><pubDate>Tue, 28 Sep 2010 07:34:00 GMT</pubDate><guid>//www.355548.live/algz/articles/333235.html</guid><wfw:comment>//www.355548.live/algz/comments/333235.html</wfw:comment><comments>//www.355548.live/algz/articles/333235.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.355548.live/algz/comments/commentRss/333235.html</wfw:commentRss><trackback:ping>//www.355548.live/algz/services/trackbacks/333235.html</trackback:ping><description><![CDATA[<p>EOS提供?lt;l:iterator/>标签Q可以对数组集合q行q代?br /> iterate标签的实现原理是Ҏl或集合q行q代Q每ơ把子元素放在page数据区指定的节点下。这个节点名U由iterate标签的id</p> <p>属性来指定?br /> <%=  ((DataObject)pageContext.getAttribute("id1")).getString("paramDictname") %></p> <img src ="//www.355548.live/algz/aggbug/333235.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.355548.live/algz/" target="_blank">紫蝶∏飛揚↗</a> 2010-09-28 15:34 <a href="//www.355548.live/algz/articles/333235.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JS控制的页面回退 - 棒球比分大小怎么算|վ//www.355548.live/algz/articles/333027.html紫蝶∏飛揚↗紫蝶∏飛揚↗Mon, 27 Sep 2010 02:11:00 GMT//www.355548.live/algz/articles/333027.html//www.355548.live/algz/comments/333027.html//www.355548.live/algz/articles/333027.html#Feedback0//www.355548.live/algz/comments/commentRss/333027.html//www.355548.live/algz/services/trackbacks/333027.html onclick="javascript:history.go(-1);"

]]>
JSP常用的取相对路径 - 棒球比分大小怎么算|վ//www.355548.live/algz/articles/333025.html紫蝶∏飛揚↗紫蝶∏飛揚↗Mon, 27 Sep 2010 02:10:00 GMT//www.355548.live/algz/articles/333025.html//www.355548.live/algz/comments/333025.html//www.355548.live/algz/articles/333025.html#Feedback0//www.355548.live/algz/comments/commentRss/333025.html//www.355548.live/algz/services/trackbacks/333025.html //127.0.0.1:8090/eos-default/dataset/taskdistribute/taskdistribute.jsp
var str="<%=request.getContextPath()%>"+"/dataset/taskdistribute/taskdistribute.jsp";

]]>
select元素获取选择前的?/title><link>//www.355548.live/algz/articles/319749.html</link><dc:creator>紫蝶∏飛揚↗</dc:creator><author>紫蝶∏飛揚↗</author><pubDate>Fri, 30 Apr 2010 01:22:00 GMT</pubDate><guid>//www.355548.live/algz/articles/319749.html</guid><wfw:comment>//www.355548.live/algz/comments/319749.html</wfw:comment><comments>//www.355548.live/algz/articles/319749.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.355548.live/algz/comments/commentRss/319749.html</wfw:commentRss><trackback:ping>//www.355548.live/algz/services/trackbacks/319749.html</trackback:ping><description><![CDATA[<p>在focus事g里保存初?change事g里进行新g旧值的比较<br /> ....... <br /> <SELECT NAME="myselect" ONFOCUS="SelectValue=this.value" ONCHANGE="alert('上次选择的是'+SelectValue)"> <br /> <OPTION VALUE="1111">1111 <br /> <OPTION VALUE="2222">2222 <br /> <OPTION VALUE="3333">3333 <br /> </SELECT> <br /> ....... <br /> </p> <img src ="//www.355548.live/algz/aggbug/319749.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.355548.live/algz/" target="_blank">紫蝶∏飛揚↗</a> 2010-04-30 09:22 <a href="//www.355548.live/algz/articles/319749.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EL表达式解军_LIST问题{问?/title><link>//www.355548.live/algz/articles/319717.html</link><dc:creator>紫蝶∏飛揚↗</dc:creator><author>紫蝶∏飛揚↗</author><pubDate>Thu, 29 Apr 2010 09:46:00 GMT</pubDate><guid>//www.355548.live/algz/articles/319717.html</guid><wfw:comment>//www.355548.live/algz/comments/319717.html</wfw:comment><comments>//www.355548.live/algz/articles/319717.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.355548.live/algz/comments/commentRss/319717.html</wfw:commentRss><trackback:ping>//www.355548.live/algz/services/trackbacks/319717.html</trackback:ping><description><![CDATA[<logic:iterate id="employeeWage" name="<span style="color: #99cc00">employeeWageList</span>"  indexId="<span style="color: #339966">index</span>">   <span style="color: #008000">//也可以用jstl c:标签</span><br /> <input align="right" name="employeeWageMoney" style="text-align: right;width: 60px" value="${<span style="color: #99cc00">modifyEmployeeWageList</span>[<span style="color: #339966">index</span>].employeeWageMoney }" /> ?br /> </logic:iterate ><br /> <br /> 有时目中两个同cd的对象需要传值给界面比对,此时qC.主要技术就是EL表达式可以直接取for的参数?要相信一?JSP也好,标签也好.都要转化为SERVLETc?也就是一个JAVAc?所以定义的属性或Ҏ都可以通用?EL寚w合的取法[],对于LIST{都通用. <img src ="//www.355548.live/algz/aggbug/319717.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.355548.live/algz/" target="_blank">紫蝶∏飛揚↗</a> 2010-04-29 17:46 <a href="//www.355548.live/algz/articles/319717.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]Jsp中实现文件上传与下蝲 - 棒球比分大小怎么算|վ//www.355548.live/algz/articles/308091.html紫蝶∏飛揚↗紫蝶∏飛揚↗Sun, 03 Jan 2010 08:54:00 GMT//www.355548.live/algz/articles/308091.html//www.355548.live/algz/comments/308091.html//www.355548.live/algz/articles/308091.html#Feedback1//www.355548.live/algz/comments/commentRss/308091.html//www.355548.live/algz/services/trackbacks/308091.html 

Jsp中实现文件上传与下蝲  

1Q客L上传文g
   
客户端通过一个Jsp面Q上传文件到服务器,该Jsp面必须含有Filec表单,q且表单必须讄enctype="multipart/form- data"。提交表单时通过内置对象requestQrequest.getInputStream();Ҏ获得一个输入流?br />     在上传文件时Q会有附加信息,如下所C:

-----------------------------7d71042a40328
Content-Disposition: form-data; name="fileforload"; filename="C:"Documents and Settings"ZJ"
桌面"book.txt"
Content-Type: text/plain
//此处为文件内?br /> -----------------------------7d71042a40328
Content-Disposition: form-data; name="submit"

commit
-----------------------------7d71042a40328--

    附加信息大小?97字节Q不定q个|试得到Q,可通过request.getContentLength()>297来判断是否上传了文gq是提交I字W串?/span>

2Q测?/span>
    fileupload.jsp
负责提交文gQaccept.jsp负责实现上传功能?br /> fileupload.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>This page for FileUpload</title>
</head>
<body>
<p>Choose the file for uploading:
<form action="accept.jsp" method=post enctype="multipart/form-data">
  <input type=file name=fileforload size=30>
  <br>
  <input type=submit value=commit name=submit>
</form>
</body>
</html>

accept.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>This page for response</title>
</head>
<body>
<%try{
 if(request.getContentLength()>297){
   InputStream in=request.getInputStream();
   File f=new File("d:/temp","test.txt");
   FileOutputStream o=new FileOutputStream(f);
   byte b[]=new byte[1024];
   int n;
   while((n=in.read(b))!=-1){
  o.write(b,0,n);
   }
   o.close();
   in.close();
   out.print("File upload success!");
 }
 else{
  out.print("No file!");
 }
}
catch(IOException e){
 out.print("upload error.");
 e.printStackTrace();
}
%>
</body>
</html>

    服务器端得到的上传文件I like.txtQ取名ؓtest.txt

-----------------------------7d75b1540328
Content-Disposition: form-data; name="fileforload"; filename="C:"Documents and Settings"ZJ"
桌面"I like.txt"
Content-Type: text/plain

我喜Ƣ驾驭着代码在风驰电掣中创造完?
我喜Ƣ操U늝代码在随心所Ʋ中体验生活;
我喜Ƣ用心情代码~制我小的与众不同;
每一D|的代码在我手中g生对我来说就象观看刹那花开的感?
我不需要焦?因ؓ我就是焦?

-----------------------------7d75b1540328
Content-Disposition: form-data; name="submit"

commit
-----------------------------7d75b1540328--

3Q去除附加信?/span>
   
按照HTTP协议Q文件表单提交的信息中,??不的自动空?和后5行是表单本n的信息,中间部分才是上传的文件的内容。下例对上传的文件进行处理,获取文g名,q去除附加信息?/span>

4Q测?/span>
    fileupload.jsp
不变Q?u>accept.jsp修改如下Q?/span>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>The real file</title>
</head>
<body>
<%try{
 //use sessionid to create a temp file.
 String tempFileName=(String)session.getId();
 //create the temp file.
 File temp=new File("d:/temp",tempFileName);
 FileOutputStream o=new FileOutputStream(temp);
 if(request.getContentLength()>297){
   //write the upload content to the temp file.
   InputStream in=request.getInputStream();
   byte b[]=new byte[1024];
   int n;
   while((n=in.read(b))!=-1){
    o.write(b,0,n);
   }
   o.close();
   in.close();
   //read the temp file.
   RandomAccessFile random=new RandomAccessFile(temp,"r");
   //read Line2 to find the name of the upload file.
   int second=1;
   String secondLine=null;
   while(second<=2){
    secondLine=random.readLine();
    second++;
   }
   //get the last location of the dir char.'""'.
   int position=secondLine.lastIndexOf('""');
   //get the name of the upload file.
   String fileName=secondLine.substring(position+1,secondLine.length()-1);
   //relocate to the head of file.
   random.seek(0);
   //get the location of the char.'Enter' in Line4.
   long forthEndPosition=0;
   int forth=1;
   while((n=random.readByte())!=-1&&(forth<=4)){
    if(n=='"n'){
     forthEndPosition=random.getFilePointer();
     forth++;
    }
   }
   File realFile=new File("d:/temp",fileName);
   RandomAccessFile random2=new RandomAccessFile(realFile,"rw");
   //locate the end position of the content.Count backwards 6 lines.
   random.seek(random.length());
   long endPosition=random.getFilePointer();
   long mark=endPosition;
   int j=1;
   while((mark>=0)&&(j<=6)){
    mark--;
    random.seek(mark);
    n=random.readByte();
    if(n=='"n'){
     endPosition=random.getFilePointer();
     j++;
    }
   }
   //locate to the begin of content.Count for 4 lines's end position.
   random.seek(forthEndPosition);
   long startPoint=random.getFilePointer();
   //read the real content and write it to the realFile.
   while(startPoint<endPosition-1){
    n=random.readByte();
    random2.write(n);
    startPoint=random.getFilePointer();
   }
   random2.close();
   random.close();
   //delete the temp file.
   temp.delete();
   out.print("File upload success!");
 }
 else{
  out.print("No file!");
 }
}
catch(IOException e){
 out.print("upload error.");
 e.printStackTrace();
}
%>
</body>
</html>

    Q注Q如果文件名是中文,会出Cؕ码。)

5Q文件下?/span>
    Jsp
内置对象response调用ҎgetOutputStreamQ)可以获取一个指向客L输出,服务器将文g写入q个,然后可下载此文g?/span>

6Q测?/span>
    download.jsp
昄下蝲选项QLoadFile.javaQServletQ负责下载文件?br /> download.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>download page</title>
</head>
<body>
<a href=loadFile>Download:test.zip</a>
</body>
</html>

LoadFile.java

package com.zj.sample;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class LoadFile extends HttpServlet{
 public void doGet(HttpServletRequest request,HttpServletResponse response)
   throws IOException,ServletException{
    OutputStream o=response.getOutputStream();
    byte b[]=new byte[1024];
    //the file to download.
    File fileLoad=new File("d:/temp","test.rar");
    //the dialogbox of download file.
    response.setHeader("Content-disposition",
      "attachment;filename="+"test.rar");
    //set the MIME type.
    response.setContentType("application/x-tar");
    //get the file length.
    long fileLength=fileLoad.length();
    String length=String.valueOf(fileLength);
    response.setHeader("Content_Length",length);
    //download the file.
    FileInputStream in=new FileInputStream(fileLoad);
    int n=0;
    while((n=in.read(b))!=-1){
     o.write(b,0,n);
    }
 }
 public void doPost(HttpServletRequest request,HttpServletResponse response)
 throws IOException,ServletException{
  doGet(request,response);
 }

}

web.xmlQ注册servletQ?/span>

<servlet>
  <servlet-name>LoadFileServlet</servlet-name>
  <servlet-class>com.zj.sample.LoadFile</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>LoadFileServlet</servlet-name>
  <url-pattern>/loadFile</url-pattern>
</servlet-mapping>


                                                                                 转自Q-//blog.csdn.net/lookthesea/archive/2007/05/20/1617633.aspx

]]>
{ganrao}