零度空间

To feel the crazy world

2009年4月15日

最近要用到iText来处理PDF来提供User与服务器交互的途径, 所以从Google和Baidu上翻了翻,学到了一点东西, 想Mark下来以后参考,同时也可以和大家交流一下.

Project最主要是要解决三个方面的问题:

1.用什么Software来生成可交互的Form?
2.用什么Open source tools来Pre-fill Form?
3.在User填完Data后,又以什么方式Submit 到Server处理?

对于第一个问题,自然是用Adobe 的Software啦,但是用Acrobat Pro还是用Lifecycle Designer, 却让我费了不少劲.为什么咧?因为Acrobat Pro和Lifecycle Designer 处理的Form的格式是不一样的. Acrobat Pro里面用的是AcroForm,是Acrobat3.0开始用的格式,而Lifecycle Designer里面用的是Xfa Form,是基于XML的, 两者的不同请参考以下的摘录:      

Acroforms and XFA forms are different technologies

The interactive forms that you create in LiveCycle Designer are different than the interactive forms that you create in Adobe Acrobat. If you create an interactive form in Acrobat, your form is based on Adobe’s Acroform technology. This technology dates back to Acrobat version 3, and Adobe provides the “Acrobat Forms API Reference” to provide the technical details for this technology. I would not recommend using Acroform technology because XFA is the better technology.
 
If you are moving from Acroforms to XFA forms, you need to know a couple of important facts about these two technologies:

1.LiveCycle Designer can edit a PDF form created in Acrobat, but Acrobat cannot edit a PDF form created in Designer.

2.JavaScript works differently in these two technologies. Some of the JavaScript routines that work in Acroforms will not work in XFA forms. Adobe has documented these differences in a 43 page online PDF called, “Converting Acrobat JavaScript for Use in LiveCycle Designer Forms.” Designer is a much more robust tool for using JavaScript in your forms, so I recommend that you learn how to script with the XFA object model. See Chapter 4, “Form Scripting,” for more information.

PS: you can find more in the below link: More info about XFA


        
















 

 







Lifecycle designer 是后来才有的东西,自然是比Acrobat Pro更先进也更适合用于交互,但我的项目最终还是选了Acrobat Pro,因为我的第二个问题的答案是iText. iText可以用来Pre-fill XFA格式的Form,但是不知道为什么用iText Create的submit button不能submit XFA form(按了Button后没有反应),后来上网查到原来iText不支持XFA Form, 所以也只能用Acrobat啦.

而且用Acrobat Pro创建的Form有两个我自己觉得不错的优点(以TextFeild类型为例子):

    1. Acrobat Pro创建的AcroForm是没有层次结构的,而LifeCycle Desinger创建的Form是有层次的.什么意思咧?举个例子,同样是Add一个TextFeild, 把它命名为CustomerName,在AcroForm里面的名字就是CustomerName啦,而在XFA Form里面就成了topmostSubForm[0].Page1[0].CustomerName[0],咋一看,还真是烦.而且你的PDF一改的话,那你的Feild name也相应改了,这样Program也要改了....
    2. Acrobat Pro创建的AcroForm的TextFeild可以自适应大小,一个TextFeild总是有一定的长度,但要填的Value就不知有多长啦,有可能有个CustomerName真的很长咧,这在XFA Form里面就会有些Value Show不出来,但Acrobat Pro创建的AcroForm的TextFeild就可以根据Value的大小而改变字体的大小来适应TextFeild的长度.

以上两点是我自己的认识,也许Lifecycle Designer也可以做到以上的效果,但目前我是不会,因为接触Lifecycle Designer比较少,如果有大虾知道的话请多多指教.

posted @ 2009-04-15 11:32 KenLee 阅读(696) | 评论 (2)编辑 收藏

2009年2月6日

今天碰到了个比较奇怪的问题,居然是因为JSP太大导致文件编译不了,上网查了一下,把解决方法贴下来,以供以后参考:

The problem is that there is a limit on the size of a compiled method in a
Java class file, and that limit is what we're running up against. Recall
that a JSP page is compiled into a servlet, and into essentially only one
method in that servlet. Hence, if your page contains many, many tags, that
method becomes too big, and up comes the exception that you're seeing.

There are a couple of (partial) solutions.

1) Break your giant page up into multiple smaller pages and bring them
together at run time using <jsp:include>. Note that <%@include> won't work,
because that's a compile-time include, which will get you straight back to
the original problem.

2) Look for places to save on tags. For example, the <html:option> tag was
recently extended to allow the specification of the text to display, so
that you can replace this:

<html:option ... ><bean:message key="foo"/></html:option>

with this:

<html:option ... key="foo"/>

More info pls access this link: Solution

我就是用了第一种方法解决的,之前include JSP的时候用了%@include, 后来用了<jsp:include>就不会用问题了.顺便贴一下两者的区别:


@include & jsp:include的区别
引用:http://www.ibm.com/developerworks/cn/java/j-jsp04293/

本文是 Java Brett McLaughlin 继第一篇 JSP 最佳实践文章后的后续文章,在文中,作者向您演示了如何扩展 JSP 技术中用于动态内容的包含功能。了解静态 include 伪指令和动态 jsp:include 元素之间的差异,搞清楚如何混合搭配这二者以获取最优性能。
在新的 JSP 最佳实践系列的前一篇文章中,您了解了如何使用 JSP include 伪指令将诸如页眉、页脚和导航组件之类的静态内容包含到 Web 页面中。和服务器端包含一样,JSP include 伪指令允许某个页面从另一个页面提取内容或数据。

清单 1. JSP include 伪指令

<%@ page language="java" contentType="text/html" %>
<html>
<head>
      <title>newInstance.com</title>
      <meta http-equiv="Content-Type"
        content="text/html; charset=iso-8859-1" />
      <link href="/styles/default.css"
        rel="stylesheet" type="text/css" />
</head>
<body>
<%@ include file="header.jsp" %>
<%@ include file="navigation.jsp" %>
<%@ include file="bookshelf.jsp" %>
<%@ include file="/mt-blogs/index.jsp" %>
<%@ include file="footer.jsp" %>
</body>
</html>



虽然 include 非常适于将静态内容并入 Web 页面,但对于动态内容却不尽如人意。我们在前一篇文章中在试图重新装入高速缓存文件时发现了这一问题。与大多数页眉文件及页脚文件不同,动态内容变化频繁,必须时刻更新。我们将首先扼要地重述一下 include 伪指令的局限性,然后我将向您演示如何用 jsp:include 标记来扩展 JSP 的包含能力。


高速缓存问题

JSP include 伪指令的不足之处有一个是:它会导致 Web 浏览器高速缓存所有页面。在处理诸如页脚、版权声明或一组静态链接之类的静态组件时,这是有意义的。这些文件不会改变,因此没有理由让 JSP 解释器不断地重新轮询其中的数据。凡是可能的地方,都应该实现高速缓存,因为它改善了应用程序的性能。


但是,有时侯,进行高速缓存会得不偿失。如果提入的内容来自使用动态数据(如 Weblog 或数据库驱动的 JSP 文件)的程序,甚至如果所包含的内容是经常变化的 HTML(如时间戳记),那么每当装入 Web 页面时,都需要显示这些文件或程序的最新版本。遗憾的是,JSP include 伪指令并不具备这一功能。在测试和开发周期中,在浏览器中禁用高速缓存通常能够解决这一问题。但是,对于实际使用的应用程序而言,性能是任何设计决策过程中的一项重要因素,禁用高速缓存并不是一种可行的长远之计。更好的解决方案是使用 jsp:include 标记。

jsp:include 标记

jsp:include 只不过是一个不同于 include 的伪指令而已。 jsp:include 的优点在于:它 总是会检查所含文件中的变化。过一会儿我们将研究这一新标记的工作方式。但首先看一下两种 include 各自的代码,以便能够看到二者之间的异同。

清单 2 显示了一个简单页面,它使用了原始的 JSP include 伪指令。


清单 2. JSP include 伪指令

<%@ page language="java" contentType="text/html" %>
<html>
     <head>
      <title>JSP include element test</title>
     </head>
     <body>
      This content is statically in the main JSP file.<br />
      <%@ include file="included.html" %>
     </body>
</html>


清单 3 是同一个页面,只不过这里转成使用 jsp:include 标记。


清单 3. 转成使用 jsp:include

<%@ page language="java" contentType="text/html" %>
<html>
     <head>
      <title>JSP include element test</title>
     </head>
     <body>
      This content is statically in the main JSP file.<br />
      <jsp:include page="included.html" flush="true" />
     </body>
</html>


您应该注意这两种代码类型之间的两大区别。首先, jsp:include 元素不使用属于 include 伪指令的 %@ 语法。实际上, jsp 前缀让 JSP 编译器知道:它应该寻找标准 JSP 标记集中的元素。其次,指定要包含的文件的属性从 file 变成了 page 。


flush 属性

您可能已注意到 jsp:include 代码示例中的 flush 属性。顾名思义, flush 指示在读入包含内容之前是否清空任何现有的缓冲区。JSP 1.1 中需要 flush 属性,因此,如果代码中不用它,会得到一个错误。但是,在 JSP 1.2 中, flush 属性缺省为 false。由于清空大多数时候不是一个重要的问题,因此,我的建议是:对于 JSP 1.1,将 flush 设置为 true;而对于 JSP 1.2 及更高版本,将其设置为关闭。


jsp:include 是如何工作的

如果您有点爱刨根问底,那么可能十分想知道 jsp:include 标记的行为为什么与 include 伪指令不同。道理其实十分简单: jsp:include 包含的是所包含 URI 的 响应,而不是 URI 本身。这意味着:对所指出的 URI 进行 解释,因而包含的是 生成的响应。如果页面是 HTML,那么将得到一点也没有变化的 HTML。但是,如果是 Perl 脚本、Java servlet 或者 CGI 程序,那么得到的将是从该程序解释而得的结果。虽然页面通常就是 HTML,但实际程序恰好是达到目的的手段。而且,由于每次请求页面的时候都会进行解释,因此从来不会象使用 include 伪指令时那样高速缓存结果。虽然这只是很小的变动,但它却导致了您所见到的行为中的全部差异。


一种混合搭配的解决方案

include 伪指令在某些网站上有其用武之地。例如,如果站点包含一些(如果有变化,也很少)几乎没有变化的页眉、页脚和导航文件,那么基本的 include 伪指令是这些组件的最佳选项。由于 include 伪指令采用了高速缓存,因此只需放入包含文件一次,其内容就会被高速缓存,其结果会是极大地提高了站点的性能。

然而,对于现在许多 Web 应用程序或站点而言,地毯式的高速缓存并不能解决问题。虽然页眉和页脚可能是静态的,但是不可能整个站点都是静态的。例如,从数据库提取导航链接是很常见的,并且许多基于 JSP 技术的站点还从其它站点或应用程序上的动态 JSP 页面提取内容。如果正在处理动态内容,那么需要采用 jsp:include 来处理该内容。

当然,最好的解决方案是经常把这两种方法混合搭配使用,将每种构造用到最恰当的地方。清单 4 是混合搭配包含解决方案的一个示例。

清单 4. 混合搭配解决方案

<%@ page language="java" contentType="text/html" %>
<html>
<head>
<title>newInstance.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/styles/default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<jsp:include page="header.jsp" flush="true">
<jsp:param name="pageTitle" value="newInstance.com"/>
<jsp:param name="pageSlogan" value=" " />
</jsp:include>
<%@ include file="/navigation.jsp" %>
<jsp:include page="bookshelf.jsp" flush="true" />
<jsp:include page="/mt-blogs/index.jsp" flush="true" />
<%@ include file="/footer.jsp" %>
</body>
</html>


上面的代码显示了前一篇文章中的示例索引页面。导航链接和页脚是静态内容,一年最多更改一次。对于这些文件,我使用了 include 伪指令。内容窗格包含 Weblog 和“bookshelf”组件,它们是动态生成的。这两个组件需要一直更新,因此对它们,我使用了 jsp:include 标记。 header.jsp 文件有点奇怪。这个组件是从另一个本质上是静态的 JSP 页面提取的。但是,正如您将注意到的那样,它从包含页提取页“标语”,然后将它显示出来。要处理这一共享信息,我们必须向页眉文件传入参数。而要处理那些参数,就必须使用 jsp:include 元素。

 
后记:网上还有一种Solution:

try giving this in the deployment descriptor.

<jsp-param>
<param-name>noTryBlocks</param-name>
<param-value>true</param-value>
</jsp-param>

本人没有试过, 不知好不好用....

posted @ 2009-02-06 18:33 KenLee 阅读(1215) | 评论 (1)编辑 收藏
仅列出标题  

导航

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

统计

常用链接

留言簿(2)

随笔分类

随笔档案

Tech

搜索

最新评论

阅读排行榜

评论排行榜