- 浏览: 255695 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (217)
- java 基础 (36)
- flex (1)
- structs 2.0 (5)
- oracle 学习过程 (20)
- j2ee (63)
- c/s java (0)
- javaScript (24)
- jdom (1)
- jquery (1)
- java模式 (1)
- Datebase common konwledge (3)
- JfreeChart (3)
- html (3)
- sql server (6)
- tomcat servlet (4)
- lucene (1)
- Linux (3)
- 常见注意 (6)
- hibernate (2)
- jsp页面 (3)
- effective Java (1)
- spring (2)
- Spark (1)
- json (0)
- JMS (1)
- 电脑故障 (2)
- mysql (1)
- JBPM (2)
- java 线程 (1)
- oracle优化 (1)
- 安全 (1)
- hadoop (0)
- 算法 (1)
- hbase (0)
最新评论
-
mfhappy:
你好,你这个导出的文件中如果有图片你怎么处理??
jsp 导出excel(利用excel本身另存为html) -
丹寺丁:
...
jquery 解析 java 后台的 json数据 -
xurichusheng:
不直接诶生成想要的对象,而是让客户端利用所有必要的参数 ...
重叠构造器、Builder模式 -
wen121221222:
感谢啊!困恼我一个下午的问题终于解决了
java.lang.NoClassDefFoundError: javax/mail/Authenticator异常 -
gaoyanglovejava:
不错。就是这么解决的。多谢
The project is not a myEclipse hibernate project
测试应用
public void getReader() throws IOException{ URL url=getClass().getClassLoader().getResource("fold1/tools/test.properties"); InputStream is= url.openStream(); Reader read=new InputStreamReader(is); PropertiesReader pr=new PropertiesReader(read); while(pr.nextProperty()){ String name=pr.getPropertyName(); String value=pr.getPropertyValue(); } }
中文编码重点: \u 开头 将\u后面的部分利用 Integer.Parseint(.toString,16); 按16进制转成整数
再把整数转成char,即得到汉字
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package fold1.tools; import java.io.*; import java.util.ArrayList; import java.util.List; /** * This class is used to read properties lines. These lines do * not terminate with new-line chars but rather when there is no * backslash sign a the end of the line. This is used to * concatenate multiple lines for readability. * * This class was pulled out of Jakarta Commons Configuration and * Jakarta Commons Lang trunk revision 476093 */ public class PropertiesReader extends LineNumberReader { /** Stores the comment lines for the currently processed property.*/ private List<String> commentLines; /** Stores the name of the last read property.*/ private String propertyName; /** Stores the value of the last read property.*/ private String propertyValue; /** Stores the list delimiter character.*/ private char delimiter; /** Constant for the supported comment characters.*/ static final String COMMENT_CHARS = "#!"; /** Constant for the radix of hex numbers.*/ private static final int HEX_RADIX = 16; /** Constant for the length of a unicode literal.*/ private static final int UNICODE_LEN = 4; /** The list of possible key/value separators */ private static final char[] SEPARATORS = new char[] {'=', ':'}; /** The white space characters used as key/value separators. */ private static final char[] WHITE_SPACE = new char[]{' ', '\t', '\f'}; /** * Constructor. * * @param reader A Reader. */ public PropertiesReader(Reader reader) { this(reader, ','); } /** * Creates a new instance of <code>PropertiesReader</code> and sets * the underlaying reader and the list delimiter. * * @param reader the reader * @param listDelimiter the list delimiter character * @since 1.3 */ public PropertiesReader(Reader reader, char listDelimiter) { super(reader); commentLines = new ArrayList<String>(); delimiter = listDelimiter; } /** * Tests whether a line is a comment, i.e. whether it starts with a comment * character. * * @param line the line * @return a flag if this is a comment line * @since 1.3 */ boolean isCommentLine(String line) { String s = line.trim(); // blanc lines are also treated as comment lines return s.length() < 1 || COMMENT_CHARS.indexOf(s.charAt(0)) >= 0; } /** * Reads a property line. Returns null if Stream is * at EOF. Concatenates lines ending with "\". * Skips lines beginning with "#" or "!" and empty lines. * The return value is a property definition (<code><name></code> * = <code><value></code>) * * @return A string containing a property value or null * * @throws IOException in case of an I/O error */ public String readProperty() throws IOException { commentLines.clear(); StringBuilder buffer = new StringBuilder(); while (true) { String line = readLine(); if (line == null) { // EOF return null; } if (isCommentLine(line)) { commentLines.add(line); continue; } line = line.trim(); if (checkCombineLines(line)) { line = line.substring(0, line.length() - 1); buffer.append(line); } else { buffer.append(line); break; } } return buffer.toString(); } /** * Parses the next property from the input stream and stores the found * name and value in internal fields. These fields can be obtained using * the provided getter methods. The return value indicates whether EOF * was reached (<b>false</b>) or whether further properties are * available (<b>true</b>). * * @return a flag if further properties are available * @throws IOException if an error occurs * @since 1.3 */ public boolean nextProperty() throws IOException { String line = readProperty(); if (line == null) { return false; // EOF } // parse the line String[] property = parseProperty(line); propertyName = unescapeJava(property[0]); propertyValue = unescapeJava(property[1], delimiter); return true; } /** * Returns the comment lines that have been read for the last property. * * @return the comment lines for the last property returned by * <code>readProperty()</code> * @since 1.3 */ public List<String> getCommentLines() { return commentLines; } /** * Returns the name of the last read property. This method can be called * after <code>{@link #nextProperty()}</code> was invoked and its * return value was <b>true</b>. * * @return the name of the last read property * @since 1.3 */ public String getPropertyName() { return propertyName; } /** * Returns the value of the last read property. This method can be * called after <code>{@link #nextProperty()}</code> was invoked and * its return value was <b>true</b>. * * @return the value of the last read property * @since 1.3 */ public String getPropertyValue() { return propertyValue; } /** * Checks if the passed in line should be combined with the following. * This is true, if the line ends with an odd number of backslashes. * * @param line the line * @return a flag if the lines should be combined */ private boolean checkCombineLines(String line) { int bsCount = 0; for (int idx = line.length() - 1; idx >= 0 && line.charAt(idx) == '\\'; idx--) { bsCount++; } return bsCount % 2 == 1; } /** * Parse a property line and return the key and the value in an array. * * @param line the line to parse * @return an array with the property's key and value * @since 1.2 */ private String[] parseProperty(String line) { // sorry for this spaghetti code, please replace it as soon as // possible with a regexp when the Java 1.3 requirement is dropped String[] result = new String[2]; StringBuilder key = new StringBuilder(); StringBuilder value = new StringBuilder(); // state of the automaton: // 0: key parsing // 1: antislash found while parsing the key // 2: separator crossing // 3: value parsing int state = 0; for (int pos = 0; pos < line.length(); pos++) { char c = line.charAt(pos); switch (state) { case 0: if (c == '\\') { state = 1; } else if (contains(WHITE_SPACE, c)) { // switch to the separator crossing state state = 2; } else if (contains(SEPARATORS, c)) { // switch to the value parsing state state = 3; } else { key.append(c); } break; case 1: if (contains(SEPARATORS, c) || contains(WHITE_SPACE, c)) { // this is an escaped separator or white space key.append(c); } else { // another escaped character, the '\' is preserved key.append('\\'); key.append(c); } // return to the key parsing state state = 0; break; case 2: if (contains(WHITE_SPACE, c)) { // do nothing, eat all white spaces state = 2; } else if (contains(SEPARATORS, c)) { // switch to the value parsing state state = 3; } else { // any other character indicates we encoutered the beginning of the value value.append(c); // switch to the value parsing state state = 3; } break; case 3: value.append(c); break; } } result[0] = key.toString().trim(); result[1] = value.toString().trim(); return result; } /** * <p>Unescapes any Java literals found in the <code>String</code> to a * <code>Writer</code>.</p> This is a slightly modified version of the * StringEscapeUtils.unescapeJava() function in commons-lang that doesn't * drop escaped separators (i.e '\,'). * * @param str the <code>String</code> to unescape, may be null * @param delimiter the delimiter for multi-valued properties * @return the processed string * @throws IllegalArgumentException if the Writer is <code>null</code> */ protected static String unescapeJava(String str, char delimiter) { if (str == null) { return null; } int sz = str.length(); StringBuilder out = new StringBuilder(sz); StringBuffer unicode = new StringBuffer(UNICODE_LEN); boolean hadSlash = false; boolean inUnicode = false; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (inUnicode) { // if in unicode, then we're reading unicode // values in somehow unicode.append(ch); if (unicode.length() == UNICODE_LEN) { // unicode now contains the four hex digits // which represents our unicode character try { int value = Integer.parseInt(unicode.toString(), HEX_RADIX); out.append((char) value); unicode.setLength(0); inUnicode = false; hadSlash = false; } catch (NumberFormatException nfe) { throw new RuntimeException("Unable to parse unicode value: " + unicode, nfe); } } continue; } if (hadSlash) { // handle an escaped value hadSlash = false; if (ch == '\\') { out.append('\\'); } else if (ch == '\'') { out.append('\''); } else if (ch == '\"') { out.append('"'); } else if (ch == 'r') { out.append('\r'); } else if (ch == 'f') { out.append('\f'); } else if (ch == 't') { out.append('\t'); } else if (ch == 'n') { out.append('\n'); } else if (ch == 'b') { out.append('\b'); } else if (ch == delimiter) { out.append('\\'); out.append(delimiter); } else if (ch == 'u') { // uh-oh, we're in unicode country.... inUnicode = true; } else { out.append(ch); } continue; } else if (ch == '\\') { hadSlash = true; continue; } out.append(ch); } if (hadSlash) { // then we're in the weird case of a \ at the end of the // string, let's output it anyway. out.append('\\'); } return out.toString(); } /** * <p>Checks if the object is in the given array.</p> * * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p> * * @param array the array to search through * @param objectToFind the object to find * @return <code>true</code> if the array contains the object */ public boolean contains(char[] array, char objectToFind) { if (array == null) { return false; } for (char anArray : array) { if (objectToFind == anArray) { return true; } } return false; } /** * <p>Unescapes any Java literals found in the <code>String</code>. * For example, it will turn a sequence of <code>'\'</code> and * <code>'n'</code> into a newline character, unless the <code>'\'</code> * is preceded by another <code>'\'</code>.</p> * * @param str the <code>String</code> to unescape, may be null * @return a new unescaped <code>String</code>, <code>null</code> if null string input */ public static String unescapeJava(String str) { if (str == null) { return null; } try { StringWriter writer = new StringWriter(str.length()); unescapeJava(writer, str); return writer.toString(); } catch (IOException ioe) { // this should never ever happen while writing to a StringWriter ioe.printStackTrace(); return null; } } /** * <p>Unescapes any Java literals found in the <code>String</code> to a * <code>Writer</code>.</p> * * <p>For example, it will turn a sequence of <code>'\'</code> and * <code>'n'</code> into a newline character, unless the <code>'\'</code> * is preceded by another <code>'\'</code>.</p> * * <p>A <code>null</code> string input has no effect.</p> * * @param out the <code>Writer</code> used to output unescaped characters * @param str the <code>String</code> to unescape, may be null * @throws IllegalArgumentException if the Writer is <code>null</code> * @throws IOException if error occurs on underlying Writer */ public static void unescapeJava(Writer out, String str) throws IOException { if (out == null) { throw new IllegalArgumentException("The Writer must not be null"); } if (str == null) { return; } int sz = str.length(); StringBuffer unicode = new StringBuffer(4); boolean hadSlash = false; boolean inUnicode = false; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (inUnicode) { // if in unicode, then we're reading unicode // values in somehow unicode.append(ch); if (unicode.length() == 4) { // unicode now contains the four hex digits // which represents our unicode character try { int value = Integer.parseInt(unicode.toString(), 16); out.write((char) value); unicode.setLength(0); inUnicode = false; hadSlash = false; } catch (NumberFormatException nfe) { throw new RuntimeException("Unable to parse unicode value: " + unicode, nfe); } } continue; } if (hadSlash) { // handle an escaped value hadSlash = false; switch (ch) { case '\\': out.write('\\'); break; case '\'': out.write('\''); break; case '\"': out.write('"'); break; case 'r': out.write('\r'); break; case 'f': out.write('\f'); break; case 't': out.write('\t'); break; case 'n': out.write('\n'); break; case 'b': out.write('\b'); break; case 'u': { // uh-oh, we're in unicode country.... inUnicode = true; break; } default : out.write(ch); break; } continue; } else if (ch == '\\') { hadSlash = true; continue; } out.write(ch); } if (hadSlash) { // then we're in the weird case of a \ at the end of the // string, let's output it anyway. out.write('\\'); } } }
发表评论
-
远程调用servlet
2012-09-12 16:26 3984//发起请求、先写发送(out)、然后等待度(in) URL ... -
基于ssh的项目的单元测试
2012-08-01 13:55 978package com.csoft.ta.util; imp ... -
JBPM设计器乱码问题
2012-06-30 13:44 769修改eclipse安装跟目录下的eclipse.ini文件,在 ... -
项目中读取文件
2012-03-13 18:31 812import java.io.BufferedReader;i ... -
项目中配置log4j
2012-03-08 10:26 888<!--如果不定义webAppRootKey参数,那么w ... -
qq album
2012-01-05 23:02 1030此文章完全转自他人博客(用于个人学习记录) 这个功能的实现关 ... -
关于quartz 2.x 一些记录
2011-12-30 14:27 1195功能需要 审计(即对不同规则的定制的东西进行轮巡)如果每一个轮 ... -
JavaScript动态操作表格,添加,删除行、列及单元格
2011-12-27 16:11 799<html> <head> < ... -
jsp 导出excel(利用excel本身另存为html)
2011-12-27 16:06 4514<%@page contentType="ap ... -
jsp 导出excel
2011-11-21 16:09 894<%@page contentType="ap ... -
java mail 应用
2011-09-22 10:02 860以下全部copy from http://www.cnbl ... -
quartz 在 spring静态、动态配置
2011-09-20 14:55 1179项目要求动态改变配置时间,动态改变quartz的 cron表达 ... -
JMX简单示例
2011-09-02 16:40 901以下文章摘自网络仅供学习用 1.编写一个以MBean ... -
cron表达式
2011-08-01 16:59 832以下文章复制自他出: 一个Cron-表达式是一个由六至七个 ... -
不同数据库的数据库类型及对应的jdbc类型
2011-07-27 12:47 1205public static void main(String ... -
Dom4j的使用
2011-06-15 18:08 760Dom4j 使用简介 作 ... -
SVN update时候报错的解决办法。。Working copy not locked; this is probably a bug, please rep
2011-06-01 09:02 5141今天上午CVS服务器突然坏了。。改用svn,安装完插件,连到我 ... -
hibernate 延迟加载
2011-05-12 17:25 699延迟加载: 延迟加 ... -
hibernate 一级缓存和二级缓存
2011-05-12 17:09 889一级缓存 Hibernate框架一级缓存的特点: 1.它是hi ... -
读取Blob字段图片、并进行缩放放到页面上
2011-03-29 15:15 4167整个流程分为四步,连接oracle数据库 -> 读取bl ...
相关推荐
Struts2的安全漏洞主要包括以下几类: 1. OGNL(Object-Graph Navigation Language)表达式注入:这是Struts2最著名的漏洞类型,由于框架在处理用户输入时没有进行充分的过滤和验证,攻击者可以通过构造恶意的OGNL...
4. **struts2-convention-plugin.jar**:这是Struts2的约定优于配置插件,它简化了Action类和结果配置,使得开发者可以按照一定的命名规则来自动映射URL。 5. **struts2-plugins*.jar**:Struts2有许多插件,如...
在Struts2框架中,单元测试对于验证Action类、拦截器、结果类型以及其他核心组件的行为尤其关键。 在Struts2的4.2.4版本中,提供了专门的单元测试jar包,使得开发者能够方便地对Struts2的组件进行单元测试。这个jar...
这个"struts2 类包"集合包含了几个关键的库文件,这些文件对于理解Struts2框架的工作原理以及在实际项目中使用Struts2至关重要。 1. **freemarker-2.3.10.jar**:FreeMarker是一个强大的模板引擎,用于生成动态HTML...
2. **Action与ActionMapping**:在Struts2中,业务逻辑通常封装在Action类中。一个Action类对应一个用户请求,处理来自客户端的请求并返回结果。ActionMapping则负责配置Action与URL的映射关系,使得请求能正确路由...
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
“Struts2.3.1.2_API.chm”文档包含了Struts2框架的详细API,其中涵盖了各个主要类和接口的解释、方法签名、参数说明以及返回值类型。开发者可以通过查阅此文档,快速查找特定功能的实现方式,例如ActionSupport类,...
- **Action类详解**:Action类是Struts2的核心组件之一,负责处理用户的请求并返回相应的结果。了解如何编写Action类、设置其属性以及处理请求参数至关重要。 - **Result配置**:Result用于指定Action执行后的结果...
通常,Struts2的核心库和其他依赖库会以JAR(Java Archive)文件的形式包含在项目中,这些JAR文件包含了框架的所有类和方法。开发者需要将这些JAR文件添加到项目的类路径中,以便能够使用Struts2的功能。文件可能会...
Action类需要继承自Struts2提供的基类或实现特定接口,如`ActionSupport`。 **六、路径问题的说明** Struts2通过Action和Namespace来决定URL路径。Action的全名由Namespace和ActionName组成,例如`/admin/save`,...
Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试Struts2漏洞测试...
这些jar文件是Struts2框架运行的基础,开发者需要将它们添加到项目的类路径中,以便能够利用Struts2的各种特性。 Struts2的核心jar包包括以下几个主要部分: 1. `struts2-core.jar`:这是Struts2框架的核心库,...
6. **添加Struts2库**:将下载的Struts2库(包括struts2-core等依赖库)添加到项目的类路径中。 7. **编写第一个Action**:创建一个Action类,实现你需要的业务逻辑,并指定结果页面。 8. **编写结果页面**:创建...
struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全struts2 总结工程大全...
这个“超好的Struts2 pdf 文档”很可能包含了关于Struts2的全面介绍、核心概念、配置、拦截器、结果类型、动作类、插件、以及最佳实践等内容。 Struts2的核心概念主要包括以下几个方面: 1. **Action**:在Struts2...
- 配置Struts2:在`struts.xml`配置文件中定义Action类、结果页面和拦截器。 - 创建Action类:这是处理用户请求的核心,实现业务逻辑。 - 编写JSP页面:使用Struts2的标签库来展示数据和处理用户输入。 3. **...
2. **核心库**:`struts2-core.jar`是框架的核心,包含Action、Result、Interceptor、Freemarker模板引擎等相关类,它是Struts2运行的基石。 3. **拦截器库**:`struts2-convention-plugin.jar`和`struts2-...
"Struts2"可能是项目实例代码,包括Action类、视图文件(如JSP)、配置文件等,可以用来学习和参考Struts2的实际应用。 总的来说,Struts2+Jquery+Ajax的组合使得开发者能够构建出交互性强、响应速度快的Web应用。...
1. **Action和结果映射**:在Struts2中,Action类负责处理HTTP请求,执行业务逻辑,并通过Result来决定视图如何展示。配置文件(通常为struts.xml)定义了Action与Result的映射关系。 2. **拦截器(Interceptors)*...
struts2 chm 程序包 org.apache.struts2 接口概要 接口 说明 StrutsStatics Constants used by Struts. 类概要 类 说明 RequestUtils Request handling utility class. ServletActionContext Web-specific ...