供初学者看的java代码_confighelper.java 源代码在线查看 - 和多的 struct例子 的学习 供初学者参考 资源下载 虫虫电子下载站...

这段代码展示了如何从请求中获取与ActionForm相关联的映射和实例,以及如何转换ActionAction并生成URL。核心功能包括getActionForm(), getFormBean(), getActionForward(), 和getActionMapping()等方法。
摘要由CSDN通过智能技术生成

* this mapping, creating and stashing one if necessary. If there is no * form bean associated with this mapping, return null. * */ public ActionForm getActionForm() { // Is there a mapping associated with this request? ActionMapping mapping = getMapping(); if (mapping == null) return (null); // Is there a form bean associated with this mapping? String attribute = mapping.getAttribute(); if (attribute == null) return (null); // Look up the existing form bean, if any ActionForm instance = null; if ("request".equals(mapping.getScope())) { instance = (ActionForm) this.request.getAttribute(attribute); } else { instance = (ActionForm) this.session.getAttribute(attribute); } return instance; } /** * Return the form bean definition associated with the specified * logical name, if any; otherwise return null. * * @param name Logical name of the requested form bean definition */ public ActionFormBean getFormBean(String name) { return null; } /** * Return the forwarding associated with the specified logical name, * if any; otherwise return null. * * @param name Logical name of the requested forwarding */ public ActionForward getActionForward(String name) { return null; } /** * Return the mapping associated with the specified request path, if any; * otherwise return null. * * @param path Request path for which a mapping is requested */ public ActionMapping getActionMapping(String path) { return null; } /** * Return the form action converted into an action mapping path. The * value of the action property is manipulated as follows in * computing the name of the requested mapping: * * Any filename extension is removed (on the theory that extension * mapping is being used to select the controller servlet). * If the resulting value does not start with a slash, then a * slash is prepended. * */ public String getActionMappingName(String action) { String value = action; int question = action.indexOf("?"); if (question >= 0) value = value.substring(0, question); int slash = value.lastIndexOf("/"); int period = value.lastIndexOf("."); if ((period >= 0) && (period > slash)) value = value.substring(0, period); if (value.startsWith("/")) return (value); else return ("/" + value); } /** * Return the form action converted into a server-relative URL. */ public String getActionMappingURL(String action) { StringBuffer value = new StringBuffer(this.request.getContextPath()); // Use our servlet mapping, if one is specified String servletMapping = getServletMapping(); if (servletMapping != null) { String queryString = null; int question = action.indexOf("?"); if (question >= 0) queryString = action.substring(question); String actionMapping = getActionMappingName(action); if (servletMapping.startsWith("*.")) { value.append(actionMapping); value.append(servletMapping.substring(1)); } else if (servletMapping.endsWith("/*")) { value.append(servletMapping.substring(0, servletMapping.length() - 2)); value.append(actionMapping); } if (queryString != null) value.append(queryString); } // Otherwise, assume extension mapping is in use and extension is // already included in the action property else { if (!action.startsWith("/")) value.append("/"); value.append(action); } // Return the completed value return (value.toString()); } /** * Return the url encoded to maintain the user session, if any. */ public String getEncodeURL(String url) { if ((session != null) && (response != null)) { boolean redirect = false; if (forward != null) redirect = forward.getRedirect(); if (redirect) return response.encodeRedirectURL(url); else return response.encodeURL(url); } else return (url); } // ------------------------------------------------ Presentation API /** * Renders the reference for a HTML element */ public String getOrigRef() { // HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); if (request == null) return null; StringBuffer result = RequestUtils.requestToServerUriStringBuffer(request); return result.toString(); } /** * Renders the reference for a HTML element. */ public String getBaseRef() { if (request == null) return null; StringBuffer result = RequestUtils.requestToServerStringBuffer(request); String path = null; if (forward == null) path = request.getRequestURI(); else path = request.getContextPath() + forward.getPath(); result.append(path); return result.toString(); } /** * Return the path for the specified forward, * otherwise return null. * * @param name Name given to local or global forward. */ public String getLink(String name) { ActionForward forward = getActionForward(name); if (forward == null) return null; StringBuffer path = new StringBuffer(this.request.getContextPath()); path.append(forward.getPath()); // :TODO: What about runtime parameters? return getEncodeURL(path.toString()); } /** * Return the localized message for the specified key, * otherwise return null. * * @param key Message key */ public String getMessage(String key) { MessageResources resources = getMessageResources(); if (resources == null) return null; return resources.getMessage(RequestUtils.getUserLocale(request, null), key); } /** * Look up and return a message string, based on the specified parameters. * * @param key Message key to be looked up and returned * @param args Replacement parameters for this message */ public String getMessage(String key, Object args[]) { MessageResources resources = getMessageResources(); if (resources == null) return null; // Return the requested message if (args == null) return resources.getMessage( RequestUtils.getUserLocale(request, null), key); else return resources.getMessage( RequestUtils.getUserLocale(request, null), key, args); } /** * Return the URL for the specified ActionMapping, * otherwise return null. * * @param path Name given to local or global forward. */ public String getAction(String path) { return getEncodeURL(getActionMappingURL(path)); } // --------------------------------------------- Presentation Wrappers /** * Wrapper for getLink(String) * * @param name Name given to local or global forward. */ public String link(String name) { return getLink(name); } /** * Wrapper for getMessage(String) * * @param key Message key */ public String message(String key) { return getMessage(key); } /** * Wrapper for getMessage(String,Object[]) * * @param key Message key to be looked up and returned * @param args Replacement parameters for this message */ public String message(String key, Object args[]) { return getMessage(key, args); } /** * Wrapper for getAction(String) * * @param path Name given to local or global forward. */ public String action(String path) { return getAction(path); }}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值