呃,我记得一本书上也是这么说的,
但是我一般是用<html:link/>

解决方案 »

  1.   

    我认为,编程应遵循"最简"原则,能简单就简单,所以在这里能直接转就直接转。
    “加一个action去找forward”的目的是为要通过action加载数据,并不是为了找forward。如果不用加载Bean数据,直接接转到JSP页也是好的。
    下面是相关信息:
    ********************************为了了解楼主所说这一问题,我花了一翻功夫来收集了Struts自带的例子中<html:link >的用法。结果如下:
    <html:link action="/Logon">
      <bean:message key="change.try"/>
    </html:link>
    ----------
    <html:link action="/EditRegistration?action=Edit"><bean:message key="mainMenu.registration"/></html:link>
    ------------
    <html:link forward="logoff"><bean:message key="mainMenu.logoff"/></html:link>
    ---------
    <html:link action="/EditRegistration?action=Create"><bean:message key="index.registration"/></html:link>
    ------------
    <html:link action="/Logon"><bean:message key="index.logon"/></html:link>
    ------------
    <html:link action="/Locale?language=en">English</html:link>
    <html:link action="/Locale?language=ja" useLocalEncoding="true">Japanese</html:link>
    <html:link action="/Locale?language=ru" useLocalEncoding="true">Russian</html:link>
    ------------
    <html:link action="/Tour"><bean:message key="index.tour"/></html:link>
    --------***********************
    下面是<html:link>标签处理forward、href、page、action等参数的方法,实际上都只是生成link连接字符串:
    public static String computeURL(
            PageContext pageContext,
            String forward,
            String href,
            String page,
            String action,
            Map params,
            String anchor,
            boolean redirect)
            throws MalformedURLException {        // Validate that exactly one specifier was included
            int n = 0;
            if (forward != null) {
                n++;
            }
            if (href != null) {
                n++;
            }
            if (page != null) {
                n++;
            }
            if (action != null) {
                n++;
            }
            if (n != 1) {
                throw new MalformedURLException(messages.getMessage("computeURL.specifier"));
            }        // Look up the module configuration for this request
            ModuleConfig config =
                (ModuleConfig) pageContext.getRequest().getAttribute(Globals.MODULE_KEY);
            if (config == null) { // Backwards compatibility hack
                config =
                    (ModuleConfig) pageContext.getServletContext().getAttribute(Globals.MODULE_KEY);
                pageContext.getRequest().setAttribute(Globals.MODULE_KEY, config);
            }        // Calculate the appropriate URL
            StringBuffer url = new StringBuffer();
            HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
            if (forward != null) {
                ForwardConfig fc = config.findForwardConfig(forward);
                if (fc == null) {
                    throw new MalformedURLException(messages.getMessage("computeURL.forward", forward));
                }
                if (fc.getRedirect()) {
                    redirect = true;
                }
                if (fc.getPath().startsWith("/")) {
                    url.append(request.getContextPath());
                    url.append(forwardURL(request, fc));
                } else {
                    url.append(fc.getPath());
                }
            } else if (href != null) {
                url.append(href);
            } else if (action != null) {
         url.append(getActionMappingURL(action, pageContext));        } else /* if (page != null) */ {
                url.append(request.getContextPath());
                url.append(pageURL(request, page));
            }        // Add anchor if requested (replacing any existing anchor)
            if (anchor != null) {
                String temp = url.toString();
                int hash = temp.indexOf('#');
                if (hash >= 0) {
                    url.setLength(hash);
                }
                url.append('#');
                url.append(encodeURL(anchor));
            }        // Add dynamic parameters if requested
            if ((params != null) && (params.size() > 0)) {            // Save any existing anchor
                String temp = url.toString();
                int hash = temp.indexOf('#');
                if (hash >= 0) {
                    anchor = temp.substring(hash + 1);
                    url.setLength(hash);
                    temp = url.toString();
                } else {
                    anchor = null;
                }            // Define the parameter separator
                String separator = redirect ? "&" : "&amp;";            // Add the required request parameters
                boolean question = temp.indexOf('?') >= 0;
                Iterator keys = params.keySet().iterator();
                while (keys.hasNext()) {
                    String key = (String) keys.next();
                    Object value = params.get(key);
                    if (value == null) {
                        if (!question) {
                            url.append('?');
                            question = true;
                        } else {
                            url.append(separator);
                        }
                        url.append(encodeURL(key));
                        url.append('='); // Interpret null as "no value"
                    } else if (value instanceof String) {
                        if (!question) {
                            url.append('?');
                            question = true;
                        } else {
                            url.append(separator);
                        }
                        url.append(encodeURL(key));
                        url.append('=');
                        url.append(encodeURL((String) value));
                    } else if (value instanceof String[]) {
                        String values[] = (String[]) value;
                        for (int i = 0; i < values.length; i++) {
                            if (!question) {
                                url.append('?');
                                question = true;
                            } else {
                                url.append(separator);
                            }
                            url.append(encodeURL(key));
                            url.append('=');
                            url.append(encodeURL(values[i]));
                        }
                    } else /* Convert other objects to a string */ {
                        if (!question) {
                            url.append('?');
                            question = true;
                        } else {
                            url.append(separator);
                        }
                        url.append(encodeURL(key));
                        url.append('=');
                        url.append(encodeURL(value.toString()));
                    }
                }            // Re-add the saved anchor (if any)
                if (anchor != null) {
                    url.append('#');
                    url.append(encodeURL(anchor));
                }        }        // Perform URL rewriting to include our session ID (if any)
            if (pageContext.getSession() != null) {
                HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
                if (redirect) {
                    return (response.encodeRedirectURL(url.toString()));
                } else {
                    return (response.encodeURL(url.toString()));
                }
            } else {
                 return (url.toString());
             }    }
      

  2.   

    呵呵,也在搞struts,不过刚开始
      

  3.   

    原因应该是比较清楚的,就是配置的forward找不到合适的路径。可能是因为你的tileDefinitions配置有些什么问题。
      

  4.   

    找不到message是不是找不到"><html:message key="addmessage"/>这个里面的addmessage呀?你换成别的试试?
      

  5.   

    因为在STRUTS结构中页面跳转也代表了业务逻辑,业务逻辑和表现层:JSP分开,所以不是简单的页面跳转
      

  6.   

    同意kui(kui)的观点,如果没有业务逻辑,直接跳转到jsp就可以了