111111
精灵王
精灵王
  • 注册日期2010-12-08
  • 发帖数640
  • QQ
  • 火币1103枚
  • 粉丝120
  • 关注75
  • 社区明星
阅读:2567回复:0

j2ee-j2me tips-JSP教程,J2EE/EJB/服务器 h

楼主#
更多 发布于:2011-01-08 20:42
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","p_w_upload; filename=stats.xls");
7. 特别字符转换
 ; 替换为 ;
 < 替换为 ; 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">



更多黑客技术 黑客软件 计算机技术 编程技术 网站技术 qq技术 IT新闻 黑客基地 请访问 灯火安全联盟  灯火黑客 www.hack8888.com/bbs

喜欢0 评分0
游客

返回顶部