Struts Tiles应用程序

时间:2012-06-02 10:37:11

标签: struts tiles struts-config struts-html

我正在尝试一个tile应用程序.Below是我的代码

瓦片-defs.xml

</tiles-definitions>
        <definition name="${YOUR_DEFINITION_HERE}">
        </definition>

        <definition name="commonPage" path="/jsps/template.jsp">
            <put name="header" value="/jsps/header.jsp" />
            <put name="menu"   value="/jsps/menu.jsp" />
            <put name="body"   value="/jsps/homebody.jsp" />
            <put name="footer"  value="/jsps/footer.jsp" />
        </definition>

           <definition name="aboutUsPage" extends="commonPage">
            <put name="body" value="/jsps/aboutUsBody.jsp" />
        </definition>

    </tiles-definitions>


struts-config.xml           

  <action path="/aboutus"
        type="java.com.mbest.core.action.AboutUsAction"
        parameter="method">
        <forward name="success" path="aboutUsPage"/>        
        <forward name="failure" path="aboutUsPage"/>            
        </action>


</action-mappings>


template.jsp
    <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <html>
    <head><title></title></head>
    <body>
    <table border="1"  cellspacing="0" cellpadding="0" style="width: 98%; height: 100%">
    <tr>
        <td colspan="2">
            <tiles:insert attribute="header"/>
        </td>
    </tr>
    <tr style="height: 500px">
        <td valign="top" style="width: 200px">
            <tiles:insert attribute="menu"/>
        </td>
        <td valign="baseline" align="left">
            <tiles:insert attribute="body"/> 
    </tr>
    <tr>
        <td colspan="2">
            <tiles:insert attribute="footer"/> 
        </td>
    </tr>
    </table>
    </body>
    </html>

homebody.jsp

   <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <html>
    <head>
    <title></title>
    <style type="text/css">
    <%@include file="../css/helper.css"%>
    <%@include file="../css/dropdown.css" %>
    <%@include file="../css/default.ultimate.css" %>
    </style>
    </head>
    <body>
    <div id="header">
    <ul id="nav" class="dropdown dropdown-horizontal">
        <li><span class="dir"><html:link page="/aboutus.do?method=aboutUsPage" >About Us</html:link></span></li>
        <li><span class="dir"><a href="./">Products</a></span></li>
        <li><span class="dir"><a href="./">Infrastructure</a></span></li>
        <li><span class="dir"><a href="./">Pharmaceutical Formulations</a></span></li>
        <li><span class="dir"><a href="./">Contact Us</a></span></li>
    </ul>
    </div>
    </body>
    </html>

AboutUsAction.java
package java.com.mindbest.core.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class AboutUsAction extends DispatchAction
{
    public ActionForward aboutUsPage(ActionMapping mapping,ActionForm form,
                                HttpServletRequest request,HttpServletResponse response)throws Exception
    {
        return mapping.findForward("success");

    }

}

aboutUsBody.jsp 喂

在上面的代码中,如果我尝试使用(domainname)/example/aboutus.do访问应用程序,则会给出500错误。任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

错误消息显示:

  

错误是不能创建path / aboutus的动作实例   示

这意味着Struts无法在struts-config.xml中将您的动作类(java.com.mbest.core.action.AboutUsAction实例化。您的班级名为java.com.mindbest.core.action.AboutUsAction。显然,你得到了这个错误。

另请注意,Java包是为JRE的核心类保留的。我甚至惊讶你的编译器接受编译这样一个类,或者至少不发出任何警告。不要将您的课程放在java.**包中。