我在设置属性时遇到问题,当我运行代码时有set属性功能,有时当我再次运行时,那是行不通的。代码运行顺利但是当我清除缓存时代码再次运行良好。属性会话值是否替换?我已经尝试session invalidate不行,我尝试删除属性也不行。如何解决这个问题? 我的代码java1:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String report_name = "modules/kepesertaan/gaji/DaftarDataTarDiDataGajiInstansi.rpt";
HttpSession session = request.getSession();
// get value parameter from url
String PKDCABANG = request.getParameter("PKDCABANG");
String PKELSSBP = request.getParameter("PKELSSBP");
String PKDSSBP = request.getParameter("PKDSSBP");
String PBLTHGAJI = request.getParameter("PBLTHGAJI");
String ID = request.getParameter("ID"); // ID User Login
session.removeAttribute("report_name");
session.removeAttribute("ID");
session.removeAttribute("PKDCABANG");
session.removeAttribute("PKDSSBP");
session.removeAttribute("PKELSSBP");
session.removeAttribute("PBLTHGAJI");
try {
// send value param1 dan param2 to jsp
session.setAttribute("report_name", report_name);
session.setAttribute("ID", ID);
session.setAttribute("PKDCABANG", PKDCABANG);
session.setAttribute("PKELSSBP", PKELSSBP);
session.setAttribute("PKDSSBP", PKDSSBP);
session.setAttribute("PBLTHGAJI", PBLTHGAJI);
// send request and to jsp file
getServletContext().getRequestDispatcher("/CrystalReport-viewer.jsp").forward(request, response);
} catch (Exception e) {
System.out.println("Error: "+e);
session.invalidate();
}
}
Java2的:
代码与java1具有相同的属性会话。
JSP:
<%
String report_name = (String) session.getAttribute("report_name");
String ID = (String) session.getAttribute("ID");
String P_KDCABANG = (String) session.getAttribute("P_KDCABANG");
String P_KDSSBP = (String) session.getAttribute("P_KDSSBP");
String P_BLTHGAJI = (String) session.getAttribute("P_BLTHGAJI");
String P_KELSSBP = (String) session.getAttribute("P_KELSSBP");
String PKDCABANG = (String) session.getAttribute("PKDCABANG");
String PKELSSBP = (String) session.getAttribute("PKELSSBP");
String PKDSSBP = (String) session.getAttribute("PKDSSBP");
String PBLTHGAJI = (String) session.getAttribute("PBLTHGAJI");
ReportClientDocument reportClientDoc = new ReportClientDocument();
reportClientDoc.open(report_name, OpenReportOptions._openAsReadOnly);
ParameterFieldController parameterFieldController = reportClientDoc
.getDataDefController().getParameterFieldController();
try{
if (param1 != null){
parameterFieldController.setCurrentValue("", "param1", param1);
}
if (param2 != null){
parameterFieldController.setCurrentValue("", "param2", param2);
}
if (V_PANGKAT != null){
parameterFieldController.setCurrentValue("", "V_PANGKAT", V_PANGKAT);
}
if (ID != null) {
parameterFieldController.setCurrentValue("", "ID", ID);
}
if (P_KDCABANG != null) {
parameterFieldController.setCurrentValue("", "P_KDCABANG", P_KDCABANG);
}
if (P_KDSSBP != null) {
parameterFieldController.setCurrentValue("", "P_KDSSBP", P_KDSSBP);
}
if (P_BLTHGAJI != null) {
parameterFieldController.setCurrentValue("", "P_BLTHGAJI",
new SimpleDateFormat("yyyy-MM-dd").parse(P_BLTHGAJI));
}
if (P_KELSSBP != null) {
parameterFieldController.setCurrentValue("", "P_KELSSBP", P_KELSSBP);
}
if (PKDCABANG != null) {
parameterFieldController.setCurrentValue("", "PKDCABANG", PKDCABANG);
}
if (PKDSSBP != null){
parameterFieldController.setCurrentValue("", "PKDSSBP", PKDSSBP);
}
if (PKELSSBP != null){
parameterFieldController.setCurrentValue("", "PKELSSBP", PKELSSBP);
}
if (PBLTHGAJI != null){
parameterFieldController.setCurrentValue("", "PBLTHGAJI",
new SimpleDateFormat("yyyy-MM-dd").parse(PBLTHGAJI));
}
}catch (Exception e){
System.out.println("Errors: "+e);
}
CrystalReportViewer crystalReportPageViewer = new CrystalReportViewer();
IReportSource reportSource = reportClientDoc.getReportSource();
crystalReportPageViewer.setReportSource(reportSource);
crystalReportPageViewer.setOwnPage(true);
crystalReportPageViewer.processHttpRequest(request, response,
application, null);
%>
我尝试了java1代码并运行顺利,然后我运行java2代码并没有问题,但是当我再次运行java1时,是行不通的。在我的情况下,我创建水晶报告,并且参数未发送。错误显示:
找不到该字段.----错误代码:-2147213310错误代码 名:fieldNotFound
如何解决这个问题?会话集属性有时不起作用。