2007-09-12

jsp include 乱码问题的解决
jsp include 的文件有时候会出现乱码,经过测试发现如下方法可以修改。
第一种情况可以修改被include的文件:
1.当jsp include动态文件时(jsp文件)可以在被include的jsp文件头部加上代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
可以解决。

2.当jsp include静态文件时(html文件)可以在被include的html文件的<head></head>标签内加上代码:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
同样可以解决。
第二种情况不能够修改被include的文件:
此时可以修改tomcat的web.xml达到目的

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<jsp-config>
<jsp-property-group>
<description>
Special property group for JSP Configuration JSP
example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>

<description>
Special property group for JSP Configuration JSP
example.
</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>

</web-app>

其中
jsp-config一段是用来说明你要将包含的页面默认按照什么编码格式包含。web-app 标签的version必须是2.4的。
具体可以参见
http://www.javaworld.com.tw/jute/post/view?bid=9&id=44041&sty=1&tpg=1&age=-1


2007-07-05

如何指定tomcat中session过期时间

1. 在server.xml中定义context时采用如下定义:

<Context path="/livsorder" docBase="/home/httpd/html/livsorder"
  defaultSessionTimeOut="3600" isWARExpanded="true"
  isWARValidated="false" isInvokerEnabled="true"
  isWorkDirPersistent="false"/>

2. 在web.xml中通过参数指定:

<session-config>
<session-timeout>30</session-timeout>
</session-config>

其中30表示30分钟

3. 在程序中通过servlet api直接修改
HttpSession ses = request.getSession();
ses.setMaxInactiveInterval(10);
设置单位为秒,设置为-1永不过期。

2007-07-03

Blog搬家了!
终于受不了my.donews.com的blog服务了,现在简直是垃圾,不明白为什么换成WordPress2.0后总是出这样那样的错误,提交文章不成不说,最重要的是还会丢失文章。一个字——搬!
考察了一下三大门户的blog发现都差不多,不过看起来好像sohu的好些,但是由于一些注册名的原因,不采用他们的,至少,不作为主要的发布blog(做备份还行)
---------------------------------------------
sina的rainbow686和niarevl都被注册
163的niarevol被注册,rainbow686是以前注册的还好被保留下来
sohu的rainibow686都被注册,只有niarevol没有被注册,因此幸存niarevol@sohu.com帐号
百度的niarevol在最开始就没有了,只剩下rainbow686
---------------------------------------------
索性现在同步更新csdn,javaeye,msn,hi百度的blog,其中主要是CSDN的blog,当初离开是觉得他的blog不好用,不过现在不错,毕竟是技术社区啊。javaeye的也不错,msn和hi百度的作为blog镜像。
FeedSky的订阅地址(http://feed.feedsky.com/niarevol)我将转向CSDN的blog,今后的订阅用户看到的就是我在CSDN上发布的blog了。
CSDN : http://blog.csdn.net/rainbow686/
MSN : http://rainbow686.spaces.live.com/
javaeye: http://rainbow686.javaeye.com
hi百度 : http://hi.baidu.com/rainbow686/

:P 其中google的blogger有两个blog分别是中文和英文的。中文做为blog存档,英文作为自己没事写英文的玩。
为了宣传在凤凰(www.phoenixtv.com)也开一个blog :)

Javascript Error: submit is not a function
有时候需要用javascript提交表单,这个时候我们会用javascript:userform.submit();可是我在这样做的时候怎么也提交不成功,报出javascript错误Javascript Error: submit is not a function。百思不得其解,后来查阅资料才发现,在用userForm.submit()提交表单的时候,表单里面不能有name="submit"的元素,否则在提交的时候,该对象会和submit();方法发生混淆造成该错误!! 切记,切记!

2007-06-29

在Ibatis中调用存储过程或存储的函数。
和调用sql语句不同的是需要设置入参和出参
这篇文章已经说的很详细了。
http://www.delphibbs.com/keylife/iblog_show.asp?xid=28107
可是我配置的时候确怎么也得不到正确的结果,错误大致是“记录数太多”,查询了很多资料才发现原来Ibatis2.2之前是不支持存储过程返回CURSOR,所以请需要使用Ibatis调用存储过程并且获取记录集游标的同学注意了。下面帖一个我的配置:
-----------------------------------------------
<!-- 获取用户列表 -->
<resultMap id="rm_out_getUserList" class="java.util.HashMap">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="gname" column="gname" />
<result property="cname" column="cname" />
</resultMap>
<parameterMap id="pm_in_getUserList"
class="java.util.Map">
<parameter property="result" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="rm_out_getUserList" />
<parameter property="p_name" jdbcType="VARCHAR2" javaType="java.lang.String" mode="IN" />
<parameter property="p_gname" jdbcType="VARCHAR2" javaType="java.lang.String" mode="IN" />
<parameter property="p_cname" jdbcType="VARCHAR2" javaType="java.lang.String" mode="IN" />
</parameterMap>
<procedure id="getUserList"
parameterMap="pm_in_getUserList">
{? = call PCK_USER.F_GET_USER(?,?,?)}
</procedure>
----------------------------------------------
绿色部分要注意(配置的第一行),如果是要将结果集以map形式返回,一定要写HashMap。
google的document又变样子了.
左侧是一个树形的文件管理,右侧的主要部分列出了已有文件,顶部是一条菜单,越来越像一个资源管理器了!

2007-06-22

Ibatis中如何调用oracle存储的函数
如在oracle中有个package叫做PCK_VIEW,在PCK_VIEW里面有个F_GET_SITESNAPSHOT_TIME的函数有一个varchar2参数
-------------------------------------------
function F_GET_PARTNER_LIST(p_tmp varchar2)
return RecordSet
is
l_rs RecordSet;
begin
open l_rs for select partner from T_PARTNER order by UPPER(partner) asc;
return l_rs;
end F_GET_PARTNER_LIST;
-------------------------------------------
在ibatils里面配置调用是{ call PCK_VIEW.F_GET_SITESNAPSHOT_TIME(?) }
我确定参数都配置好了,但是调用的时候还是报错啊
-------------------------------------------
--- The error occurred in com/phoenixtv/stat/dao/ibatis/sql/realtime.xml. --- The error occurred while applying a parameter map. --- Check the stat.realtime.pm_in_getSiteSnapshotTime. --- Check the statement (update procedure failed). --- Cause: java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00221: 'F_GET_SITESNAPSHOT_TIME' is not a procedure or is undefined ORA-06550: line 1, column 7:
-------------------------------------------
怎么回事,明明数据库有这个函数啊?
但是我在jdbc中这段代码确可以调用
-------------------------------------------
Class.forName("oracle.jdbc.driver.OracleDriver");
conn =DriverManager.getConnection("jdbc:oracle:thin:@111.111.111.111:1521:stat","pass","pass");



//conn = DBConnection.ins.getConn("jdbc/StatDB");sdf.format(new Date())+1
//conn = DBConnection.ins.getConn("statistic");

cs = conn.prepareCall("{? = call PCK_VIEW.F_GET_SITESNAPSHOT_TIME(?)}");
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.setString(2,"");
cs.execute();
rs =(ResultSet) cs.getObject(1);
--------------------------------------------