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

📄 base.java

📁 tbuy1.1.5是在netbeans环境下用JSF技术编写的一个论坛tbuy1.1.5是在netbeans环境下用JSF技术编写的一个论坛
💻 JAVA
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! * * 该类是所有Bean的基类,实现了一些简便的操作及几个抽象类 */package biz.tbuy.common;import java.io.Serializable;import javax.el.ELContext;import javax.el.ExpressionFactory;import javax.el.ValueExpression;import javax.faces.application.Application;import javax.faces.context.FacesContext;import javax.servlet.http.HttpServletRequest;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public abstract class Base implements Serializable{    public Base() {    }        /**     * 有助于键盘保养     * @param x     */    public void out(Object x) {        System.out.println(x);    }        /**     * 用于帮助调试request     */    public void printRequest() {        HttpServletRequest request = (HttpServletRequest)                 getFacesContext().getExternalContext().getRequest();        out("requestURI=" + request.getRequestURI());        out("requestURL=" + request.getRequestURL().toString());    }    /**     * @return FacesContext     */    public static FacesContext getFacesContext() {        return FacesContext.getCurrentInstance();    }        /**     * @return Application     */    public static Application getApplication() {        return getFacesContext().getApplication();    }        /**     * @return ELContext     */    public static ELContext getELContext() {        return getFacesContext().getELContext();    }        /**     * 简化上下文件路径的获取.     * @return contextPath 如:/tbuy     */    public String getContextPath() {        return getFacesContext().getExternalContext().getRequestContextPath();    }        /**     * 该方法用于获取网站全局信息的管理器     * 用于application的ComApplication包含着当前主站的全局信息     * @return ComApplication     */    public static ComApplication getComApplication() {        return ComApplication.getInstance();    }        /**     * 简化visitor的获取,没有则创建一个     * @return Visitor     */    public static Visitor getVisitor() {        Application app = getApplication();        ELContext elc = getELContext();        ExpressionFactory ef = app.getExpressionFactory();        ValueExpression ve = ef.createValueExpression(elc,                 "#{" + Constants.VISITOR_KEY_SCOPE + Constants.VISITOR_KEY + "}",                Visitor.class);        Visitor visitor = (Visitor)ve.getValue(elc);        if (visitor == null) {            visitor = new Visitor();            ve.setValue(elc, visitor);        }        return visitor;    }        /**     * 该方法用于简化url中parameter的获得     * @param key url中参数的id     * @return value 相应key 的value,不存在则返回null;     */    public String getParameter(String key) {        String value = null;        value = getFacesContext()                .getExternalContext()                .getRequestParameterMap().get(key);        return value;    }        /**     * get ValueExpression to bundle the ManagedBean     * @param name     * @param scope (requestScope,sessionScope,applicationScope)     * @return ValueExpression     */    public ValueExpression getValueExpression(String name, String scope) {        Application app = getApplication();        ELContext elc = getELContext();        ExpressionFactory ef = app.getExpressionFactory();        ValueExpression ve = ef.createValueExpression(elc,                 "#{" + scope + "." + name + "}",                Object.class);        return ve;    }        /**     * 该方法用于指定该模块所使用的资源束名称     * @return the resource bundle name     */    public abstract String getBundle();        /**     * 该方法用于指定该模块所使用的数据库标识     * @deprecated 该方法已经被代替     * @return the database name;     */    public abstract String getDatabase();}

⌨️ 快捷键说明

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