ITeye博客

Java

共 15 篇文章

Java RMI远程调用

具体代码: 首先定义接口: public interface IService extends Remote{ /** * 声明服务端必须提供的服务 * 注意:这里要抛出RemoteException异常 */ String service(String str)throws RemoteException; } 定义实现类: @SuppressWarnings("serial") /** 必须集成UnicastRemoteObject类用于导出远程对象和获得与远程对象通信的存根 */ public class ServiceImpl extends UnicastRemoteObject …

2015-09-15 19:16 · Java

java.lang.IllegalArgumentException: Illegal group reference

public static void main(String[] args) throws Exception{ String str = "123ABC456"; String re = "7T$R"; //re= Matcher.quoteReplacement(re); System.out.println(str.replaceFirst("ABC", re)); //System.out.println("[?]$yingyt".replaceFirst("[?]", "99")); } 上述代码会直接报: Exception in thread "main" java.lang.…

2015-02-01 23:34 · Java

Java对session的监控

在Java中可以使用 javax.servlet.http.HttpSessionAttributeListener 类 来对session进行监控。 package com.eshore.ssoserver.sysmgr.action; import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; public class AttributeListenTest implements HttpSessionAttributeListener…

2015-01-12 15:37 · Java

Java获取真实的IP地址

// 获取真实IP的方法() public String getIpAddr() { String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getH…

2014-12-18 14:58 · Java

Java某个账期月的最大天数

/* * 获取某个账期月的最大天数 * param:setMonth 格式yyyyMM * return: int 该月的最大天数 */ public int getLastDayOfMonth(String setMonth){ int year=Integer.parseInt(setMonth.substring(0, 4)); int month=Integer.parseInt(setMonth.substring(4, 6)); int day = 1; Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, y…

2014-12-18 14:50 · Java

Java String类型赋值问题

今天用POI在做Excel报表时,遇到一个问题,那就是将数据写入Excel后,Excel中的公式执行完显示的结果为科学计数法。调试Excel设置,没调试成功,最后只好用代码来格式化公式的值。在格式化的工程中发现String类型的值赋值有问题。具体代码如下: public class ExcelUtil { public static void main(String[] args) throws Exception { System.out.println(new ExcelUtil().getChangeValue(-1.862645149230957E-9)); } /** *将传入的数…

2014-10-23 15:34 · Java

获取类所引用的jar包

System.out.println("HWPFDocument类引用的jar包:"+HWPFDocument.class.getProtectionDomain().getCodeSource().getLocation()); System.out.println("Range类引用的jar包:"+Range.class.getProtectionDomain().getCodeSource().getLocation()); 打印: HWPFDocument类引用的jar包:file:/C:/Users/tingyu/.m2/repository/org/apache/poi/poi-…

2014-09-04 11:35 · Java

批量修改文件名称

package mp3; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.nio.channels.FileChannel; public class UpdateFileName { public static void updateName() throws Exception{ String path="F:\电子书\三国演义\评书:袁阔成_三国演义\三国演义"; String outPath="F:\电子书\三国演义\评书:袁阔成_三国演…

2014-09-04 11:13 · Java

Java获取系统属性

package com; public class VersionDemo { public static void main(String args) { System.out.println("Java运行时环境版本 :"+System.getProperty("java.version")); System.out.println("Java运行时环境供应商:"+System.getProperty("java.vendor")); System.out.println("Java供应商的 URL:"+System.getProperty("java.vendor.url")); Sy…

2013-10-24 11:59 · Java

java.sql.SQLException: 结果集已耗尽

2013年10月21日 星期一 21时43分23秒 说明: 继上次的java.sql.SQLException: ORA-01013: user requested cancel of current operation 错误。查了两天也没查出具体原因。后在同事的建议下,延长查询时间。因为生产库不能随意重启, 于是就写了个testQuery.jsp测试页面来测试生产环境中延长脚本查询时间是否可以完全生成文件并导出: <%@page import="com.poson.cb.lib.DBConn"%> <%@page import="java.sql.Statement"%> <%@page …

2013-10-22 00:42 · Java

Java读取远程主机文件

//Java利用第三方jar包(ganymed-ssh2-build210.jar)读取远程主机文件 package com.poson.cb.web.action.bill; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader;…

2013-09-19 00:20 · Java

Java时间处理集合

package collections; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; //时间格式处理收集 public class DateFomatCollection { //1 simpleDateFormat类 /** SimpleDateFormat函数语法: G 年代标志符 y 年 M 月 d 日 h 时 在上午或下午 (1~12) H 时 在一天中 (0~23) m 分 s 秒 S…

2013-08-27 23:46 · Java

ORA-01013: user requested cancel of current operation

2013年8月19日 星期一 16时16分04秒 在做一个界面导出功能时,报以下错误: java.sql.SQLException: ORA-01013: user requested cancel of current operation at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70) at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112) at oracle.jdbc.driver.D…

2013-08-19 17:01 · Java

Java 实现一个Null接口

注: 以下代码来自:《Thinking in Java Fourth Edition》 中的第14章 14.8节中的例子。 package chapter14.typeinfo; public class Person { public final String first; public final String last; public final String address; public Person(String first,String last,String address){ this.first=first; this.last=last; this.address=ad…

2013-07-02 00:10 · Java

Java Class.forName()无法加载类

2013年6月26日 星期三 1时01分42秒 package chapter14.typeinfo; class Candy{static{System.out.println("loading Candy");}} class Gum{static{System.out.println("loading Gum");}} class Cookie{static{System.out.println("loading Cookie");}} public class SweetShop { public static void main(String args){ System.out.p…

2013-06-26 00:41 · Java