querytag.java~32~
来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· JAVA~32~ 代码 · 共 257 行
JAVA~32~
257 行
package com.sztheater.web.taglib;
import java.text.DateFormat;
import javax.servlet.jsp.*;
import javax.servlet.http.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.*;
import com.sztheater.framework.util.*;
public class QueryTag extends BodyTagSupport {
private static HashMap m_cache_cond = null;
/*属性变量信息*/
private String m_func_id = null ; //执行业务名
private String m_action_id = null ; //执行动作
private String var = "q" ;
private String m_para_set = null ; //参数压入的集合名
private String m_params = null ; //希望从request中取得值的参数名称,以;分隔
private String m_nonempty = null ; //非空参数,如果存在空,则execute=false
private String m_cond = null ;//条件值对
private boolean m_execute = true ; //外界控制是否执行
private boolean m_trace_flag= false; //跟踪标志
private boolean m_save_cond = false; //是否保存条件到session中
private int m_page_size = 0 ; // page size
private int m_page_no = 0 ;
/*自身变量信息*/
private HashMap hashPara = null ;
private ValueObject sendPack = null ;
private ValueObject recvPack = null ;
private int iSuccFlag = 0 ;
public QueryTag() {
super();
init();
}
public void init() {
m_execute = true;
m_trace_flag = false;
m_save_cond = false;
var = "q";
CommFunc.freeObj(hashPara);
hashPara = null;
}
public void release() {
init();
}
public void saveQueryCond(HashMap hashPara){
HttpServletRequest _httpRequest = null;
HttpSession _httpSession = null;
HashMap hashCond = null;
String jsp_file = null;
Object obj = null;
boolean bRefresh = false;
String sRefresh = null;
String s_session_id = null;
if(m_save_cond || hashPara==null) return ;
_httpSession = pageContext.getSession();
_httpRequest = (HttpServletRequest)pageContext.getRequest();
jsp_file = _httpRequest.getRequestURI();
if(_httpSession==null || jsp_file==null) return ;
s_session_id = _httpSession.getId();
hashCond = null;
obj = _httpSession.getAttribute(jsp_file);
if(obj!=null && obj.getClass().getName().equals("java.util.HashMap")){
hashCond = (HashMap)obj;
}
sRefresh = CommFunc.getValue(hashPara,"REFRESH_LIST" ,"" ,true);
if(sRefresh.equals("1") || sRefresh.equals("true")){
bRefresh = true;
}
if(bRefresh){
CommFunc.freeObj(hashPara);
if(hashPara!=null) hashPara.clear();
CommFunc.copyData( hashCond,hashPara);
return ;
}
_httpSession.removeAttribute(jsp_file);
CommFunc.freeObj(hashCond);
if(hashCond!=null) hashCond.clear();
hashCond = null;
_httpSession.setAttribute(jsp_file,hashPara);
}
public int doStartTag() throws JspException {
System.out.println("com.sztheater.web.taglib.ResultTag begin doStartTag!\n");
/*变量定义*/
HttpServletRequest _httpRequest = null;
HashMap hashUser = null;
HashMap hashCond = null;
boolean bRefresh = false;
String sRefresh = null;
String str_expr = null;
HttpSession _httpSession = null;
/*初始化变量*/
hashPara = null;;
try {
/*清空信息*/
_httpRequest = (HttpServletRequest)pageContext.getRequest();
if(_httpRequest==null) return EVAL_PAGE;
_httpRequest.removeAttribute(var);
/*
if(m_func_id!=null && m_func_id.equals("sysdate")){
if(m_action_id==null || m_action_id.equals("")) m_action_id="yyyy-mm-dd";
str_expr = FuncTag.getSysDate(m_action_id);
_httpRequest.setAttribute(var ,str_expr);
return EVAL_PAGE;
}*/
System.out.println("com.sztheater.web.taglib.ResultTag->doStartTag"+
" m_cond["+m_cond+"]\n");
System.out.println("com.sztheater.web.taglib.ResultTag->doStartTag"+
" m_nonempty["+m_nonempty+"]\n");
hashPara = FuncTag.getValues(m_cond);
if(hashPara==null) hashPara = new HashMap();
FuncTag.getRequestParameters(pageContext,hashPara,m_params,null);
m_execute = FuncTag.judgeNoEmpty(hashPara,m_nonempty);
System.out.println("com.sztheater.web.taglib.ResultTag->doStartTag"+
" m_execute["+m_execute+"]\n");
if(!m_execute) {
return EVAL_PAGE;
}
saveQueryCond(hashPara);
m_func_id= m_func_id.trim();
if(sendPack==null) sendPack = new ValueObject();
if(m_para_set==null) m_para_set = "data_list";
m_para_set = m_para_set.trim();
sendPack.putParam(hashPara);
if(this.m_page_size>0){
sendPack.putParam("PAGE_SIZE",String.valueOf(this.m_page_size));
}
/*从Session中取得登录用户信息*/
_httpSession = pageContext.getSession();
if(_httpSession!=null){
hashUser = (HashMap)_httpSession.getAttribute("userinfo");
}
if(hashUser!=null) {
sendPack.setUser(hashUser);
}
//设置执行的功能与动作
sendPack.setFuncID (m_func_id );
sendPack.setActionID(m_action_id );
recvPack = new ValueObject();
//执行返回结果
iSuccFlag = SysCall.execute(sendPack,recvPack);
_httpRequest.setAttribute(var ,recvPack);
}catch(Exception e){
System.out.println("执行【"+m_func_id+"】异常"+e.getMessage());
}
return EVAL_PAGE;
}
public int doEndTag() throws JspException {
JspWriter jspWriter = null;
StringBuffer sbTrace = null;
try {
//数据检验
jspWriter = pageContext.getOut();
if (jspWriter==null || !m_execute) return EVAL_PAGE;
if(m_trace_flag) {
sbTrace = new StringBuffer("");
sbTrace.append("<table>\n");
if(recvPack!=null){
sbTrace.append("<tr><td>发送:</td>\n<td><textarea rows=\"4\" name=\"QueryTag_RECV\" cols=\"85\">");
sbTrace.append("iSuccFlag="+iSuccFlag+"\n" );
sbTrace.append(recvPack.getXml());
sbTrace.append("</textarea></td></tr>\n");
}
if(sendPack!=null){
sbTrace.append("<tr><td>接收:</td>\n<td><textarea rows=\"4\" name=\"QueryTag_Send\" cols=\"85\">");
sbTrace.append(sendPack.getXml());
sbTrace.append("</textarea></td></tr>" );
}
sbTrace.append("</table>");
jspWriter.print(sbTrace.toString());
}
}catch(Exception e){
System.out.println("执行【"+m_func_id+"】异常"+e.getMessage());
}finally{
init();
if(iSuccFlag<0) {
if(sendPack!=null) sendPack.free();
sendPack = null;
}
if(sbTrace!=null){
sbTrace.delete(0,sbTrace.length());
sbTrace.setLength(0);
}
sbTrace = null;
}
if(sendPack!= null) sendPack.free();
sendPack = null;
return EVAL_PAGE;
}
//变量名称
public void setVar(String var) {
this.var = var;
}
//执行功能号
public void setFunc_id(String func_id) {
this.m_func_id = func_id;
}
//执行动作
public void setAction_id(String action_id) {
this.m_action_id = action_id;
}
//外界控制是否执行
public void setExecute(boolean bExecute) {
this.m_execute = bExecute;
}
//外界控制是否执行
public void setTrace_flag(boolean trace_flag) {
this.m_trace_flag = trace_flag;
}
//非空的参数名
public void setNonempty(String nonempty) {
this.m_nonempty = nonempty;
}
//每页显示数据行数
public void setPageSize(int iPageSize) {
this.m_page_size = iPageSize;
}
//参数压入的集合名
public void setPara_set(String para_set) {
this.m_para_set = para_set;
}
//设置参数
public void setCond(String s_cond) {
this.m_cond = s_cond;
if(this.m_cond==null || this.m_cond.trim().equals("")) this.m_cond = null;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?