⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requestutil.java

📁 一个基于Java的新闻发布系统
💻 JAVA
字号:
/*
 * Created on 2004-5-24
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package com.hope.common.util;

import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.net.URLEncoder;

import com.hope.common.util.ValueObjectUtil;

/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class RequestUtil extends BaseTag {

	/* (non-Javadoc)
	 * @see com.westerasoft.common.tag.BaseTag#generateContent()
	 */
	public String generateContent() {

		return null;
	}

	/* (non-Javadoc)
	 * @see com.westerasoft.common.tag.BaseTag#write(java.io.OutputStream)
	 */
	public void write(OutputStream output) {

	}

	/**
	 * 属性或者参数名称
	 */
	private String name;
	private String property;
	private int scope;
	private String method;

	private String parameter;

	private String attribute;

	private String defaultValue = null;

	/**
		 * 对输出进行编码
		 */
	private String encode = null;

	/**
	 * 对输出进行解码
	 */
	private String decode = null;

	public int doStartTag() {
		String outStr = "";
		if (name != null)
			try {
				//获取对象属性的值
				if (property != null)
					outStr = this.getBeanValue();
				else
					//获取参数值
					outStr = this.getParameter(name);
			} catch (Exception e) {
				e.printStackTrace();
				return SKIP_BODY;
			}

		if (method != null && method.trim().length() > 0) {
			try {
				//方法有参数时
				if (getParameter() != null)
					outStr =
						(String) ValueObjectUtil.getValueByMethodName(
							request,
							method,
							new Object[] { getParameter()});
				//方法无参数时
				else
					outStr =
						(String) (ValueObjectUtil
							.getValueByMethodName(request, method, null));

			} catch (Exception e) {
				e.printStackTrace();
				return SKIP_BODY;
			}
		}

		if (this.parameter != null) {
			try {
				outStr = (getParameterValue(parameter));

			} catch (Exception e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
				return SKIP_BODY;
			}
		}

		if (this.attribute != null) {
			try {
				outStr = (getAttributeValue(attribute));

			} catch (Exception e1) {
				// TODO 自动生成 catch 块
				return SKIP_BODY;
			}
		}
		try {
			if (this.getEncode() == null && this.getDecode() == null)
				out.print(outStr);
			else if (getEncode() != null && this.getEncode().trim().equals("true"))
				out.print(URLEncoder.encode(outStr));
			else if (getDecode() != null && this.getDecode().trim().equals("true"))
				out.print(URLDecoder.decode(outStr));

		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return SKIP_BODY;
	}

	private String getBeanValue() {
		Object obj = request.getAttribute(name);
		if (obj != null) {
			Object value = ValueObjectUtil.getValue(obj, property);
			if (value == null) {
				return this.defaultValue == null ? "" : defaultValue;
			}
			return String.valueOf(value);
		}
		return this.defaultValue == null ? "" : defaultValue;
	}

	private String getParameter(String parameter) {
		String value = request.getParameter(parameter);
		if(value == null)
		{
			value = (String)request.getAttribute(parameter);
		}
		if (value == null) {
			return this.defaultValue == null ? "" : defaultValue;
		}
		return value;

	}
	private String getParameterValue(String parameter) {
		String value = request.getParameter(parameter);
		if (value == null) {
			return this.defaultValue == null ? "" : defaultValue;
		}
		return value;

	}

	private String getAttributeValue(String attribute) {
		String value = (String) request.getAttribute(attribute);
		if (value == null) {
			return this.defaultValue == null ? "" : defaultValue;
		}
		return value;
	}

	/**
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return
	 */
	public String getProperty() {
		return property;
	}

	/**
	 * @return
	 */
	public int getScope() {
		return scope;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		name = string;
	}

	/**
	 * @param string
	 */
	public void setProperty(String string) {
		property = string;
	}

	/**
	 * @param i
	 */
	public void setScope(int i) {
		scope = i;
	}

	/**
	 * @return
	 */
	public String getMethod() {
		return method;
	}

	/**
	 * @param string
	 */
	public void setMethod(String string) {
		method = string;
	}

	/**
	 * @return
	 */
	public String getAttribute() {
		return attribute;
	}

	/**
	 * @return
	 */
	public String getParameter() {
		return parameter;
	}

	/**
	 * @param string
	 */
	public void setAttribute(String string) {
		attribute = string;
	}

	/**
	 * @param string
	 */
	public void setParameter(String string) {
		parameter = string;
	}

	/**
	 * @return
	 */
	public String getDefaultValue() {
		return defaultValue;
	}

	/**
	 * @param string
	 */
	public void setDefaultValue(String string) {
		defaultValue = string;
	}

	/**
	 * Description:
	 * @return
	 * String
	 */
	public String getDecode() {
		return decode;
	}

	/**
	 * Description:
	 * @return
	 * String
	 */
	public String getEncode() {
		return encode;
	}

	/**
	 * Description:
	 * @param string
	 * void
	 */
	public void setDecode(String string) {
		decode = string;
	}

	/**
	 * Description:
	 * @param string
	 * void
	 */
	public void setEncode(String string) {
		encode = string;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -