发新话题
打印

ssh与jor整合举例

ssh与jor整合举例

先举个例子,假设有一个应用,是按月份查询工资单,那你先设计一个简表设计器的报表模板salary.xml,在其中定义了一个数据集,sql如下:
复制内容到剪贴板
代码:
select * from salary where month=${mymonth}
其中用到一个名为 mymonth的参数,该参数就是用户在web查询时,在表单中填入的,假设该表单如下:
复制内容到剪贴板
代码:
<form action=’jor.action?file=salary.xml’>
<input name=’mymonth’></input>

</form>
这个表单,定义了一个输入框对象,名称应该是mymonth,与sql中用到的参数名相同,action属性指出报表引擎的路径及报表模板的文件名.
看看struts.xml 有关jor的配置:
复制内容到剪贴板
代码:
<action name="jor" class="jatools.struts.JORAction" method="execute">
<result name="jor">tools/reportviewer_struts.jsp</result>
</action>
JORAction.java的代码如下:
复制内容到剪贴板
代码:
public String execute() throws Exception {
return 'jor';
}
tools/reportviewer_struts.jsp
复制内容到剪贴板
代码:
<jatools:report id="_report1" template="<%=request.getParameter("file")%>" >
<%
// 将mymonth传入到报表引擎中
_report1.setParameter(request.getParameter("mymonth"));
%>

<%@ include file='toolsbar.jsp'%>
</jatools:report>
至此,小功告成!

TOP

楼上的解决办法,并不完美。
如果需求有变,用户希望查询,某个月,某类人员的工资名单,那么,按楼上的解决方案,有三个地方,需要修改:
1. 报表模板的sql查询,增加一个mytype参数
复制内容到剪贴板
代码:
   select * from salary where month=${mymonth} and type=${mytype}
2. 在form 中增加 mytype 的input
复制内容到剪贴板
代码:
    <input name=mytype>
3. 在tools/reportviewer_struts.jsp中,增加对 mytype参数的导入
复制内容到剪贴板
代码:
<%
_report1.setParameter('mymonth',request.getParameter("mymonth"));
// 将mymonth传入到报表引擎中
_report1.setParameter('mytype',request.getParameter("mytype"));
%>
我们只要优化一下,reportviewer_struts.jsp,对于任何报表参数的增减,只需要执行1,2两步即可,看如何优化:
复制内容到剪贴板
代码:
<%
for (Enumeration en = request.getParameterNames(); en.hasMoreElements();) {
                String name = (String) en.nextElement();
                job.setParameter(name, request.getParameter(name));
            }%>

TOP

jor整合ssh的时候,你们的jar包没有冲突,出现问题吗?

jor整合ssh框架出现jar冲突,后台出现的错误是: Caused by: java.lang.AbstractMethodError: org.apache.xerces.dom.ElementNSImpl.setUserData(Ljava/lang/String;
这个是因为jdk6已经有xerces的jar包,而jor的xercesImpl的jar包含xerces的jar包。冲突导致的,于是我删除jor的xercesImpl.jar。(这个jar包含xerces.jar)
删除后,报表什么内容页没有解析出来,<jatools:report>标签解析不了。
所以必须得有xercesImpl.jar。但是与JDK中的包冲突了怎么办?

TOP

这个标题和内容一点都不相关

这个标题和内容一点都不相关,伤心的走了!我去用jasperReport了

TOP

发新话题