手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>Java技术>列表

j2ee-j2me tips

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

1. 在J2EE的Servlet中定位resource的绝对地址:
getServletContext().getResource("/Web-INF/XML/requestmappings.xml").toString();

2. ServletContext 概念:
ServletContext定义了一套用于servlet与servlet 容器通信的方法函数,如获取一个文件的MIME type, 分发请求,或是写日志
一个Java虚机的一个web应用具有一个context。
在DD(deploy描述)中标志为"distributed"的web应用,一个JAVA虚机只有一个context实例。在这种情况下,context就不能用于保存global的信息。这是应考虑使用外部资源如database来保存信息
3. IE的encoding 自动选择来源
来自于header的 charset 选项
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
4. 在有些JSP中为了显示中文字符,必须将字符作如下转变:
String result = new String(transDate.getBytes("utf8"), "iso-8859-1");
5. Lost update问题(两个instance同时在看某个记录,并可能同时进行更改操作,如何避免第一个用户由于第二个用户的修改而导致的更改丢失现象)
有两种方法:

1. Soft lock.(Optimistic Concurrency)
2. Hard lock(Pessimistic Concurrency)

1. Soft lock.

In the case of Soft lock you have use an extra field called timestamp in your
database table. When you are retrieving a record from the database, you need to
store its timestamp in a temporary variable and when user hits the update link
you have to compare this timestamp with the timestamp of most recent record
available in the database. If the timestamp matches you should allow that user
to update the record (because during this spawn of time nobody has updated the
reocrd) otherwise you should display a message stating that "Record is already
updated by somone"

2. Hard lock
In the case of hardlock, while retrieving a record from the database you should
use the query in the form of "SELECT ..FOR .. UPDATE". This will prevent
another user to modify the record until the first user completes the updation.
The query I mentioned above puts a lock on that record.

In most of the cases people prefer to use the first approach.

6. 如何将数据导出到excel文件
下面这个函数可以把table输出转成excel格式
response.setHeader("content-disposition","attachment; filename=stats.xls");
7. 特殊字符转换
& 替换为 &amp;
< 替换为 & l t;
> 替换为 & g t;
" 替换为 &q u ot;
\ 替换为 &a pos;

8. 用下面的格式在jsp中封装java代码,这样可以避免<?xml...必须从头开始的限制,另外在wml中,1. url中的&必须用& a m p;代替, contenttype必须为text/vnd.wap.wml

<?xml version="1.0" encoding="utf-8"?>
<%
response.setContentType("text/vnd.wap.wml");
%>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">


上一篇: Top 15 Ant Best Practices
下一篇: 在eclipse中使用JBossIDE和xDoclet创建EJB

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!