程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> 報錯-關於Struts2的一個問題

報錯-關於Struts2的一個問題

編輯:編程解疑
關於Struts2的一個問題

大俠們,昨晚測試的時候,結果成功顯示,今天早上再來,就不成功了,後台一直報錯:

 12:41:15.562 [http-8080-3] ERROR org.apache.struts2.dispatcher.Dispatcher - Could not find action or result
/No2_Web/0
com.opensymphony.xwork2.config.ConfigurationException: There is no Action mapped for namespace [/] and action name [0] associated with context path [/No2_Web].
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) ~[xwork-core-2.3.28.jar:2.3.28]
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63) ~[struts2-core-2.3.28.jar:2.3.28]
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37) ~[struts2-core-2.3.28.jar:2.3.28]
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) ~[xwork-core-2.3.28.jar:2.3.28]
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:557) [struts2-core-2.3.28.jar:2.3.28]
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81) [struts2-core-2.3.28.jar:2.3.28]
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) [struts2-core-2.3.28.jar:2.3.28]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.41]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.41]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.41]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:6.0.41]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.41]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:6.0.41]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.41]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) [catalina.jar:6.0.41]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) [tomcat-coyote.jar:6.0.41]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) [tomcat-coyote.jar:6.0.41]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote.jar:6.0.41]
    at java.lang.Thread.run(Thread.java:619) [?:1.6.0_13]

但我的struts.xml裡並沒有名字為0的action,JSP頁面也沒有訪問0:

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="true" />
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/user" extends="struts-default">
        <!-- 用戶登錄和注冊 -->
        <action name="user*" class="customer.CustomerControl" method="user_{1}" >
            <result name="none"></result>
        </action>

        <!-- 首頁菜單區展示 -->
        <action name="menulist" class="menu.MenuControl" method="menu_list" >
            <result name="redirect" type="redirect">/index_menu.jsp</result>
        </action>
        <action name="menuhotlist" class="menu.MenuControl" method="menu_list_hot" >
            <result name="redirect" type="redirect">/index_menu.jsp</result>
        </action>

    </package>

    <package name="admin" namespace="/admin" extends="struts-default">

        <action name="adminlogin" class="admin.AdminControl" method="admin_login" >
            <result name="none"></result>
        </action>

        <action name="adminregister" class="admin.AdminControl" method="admin_register" >
            <result name="none"></result>
        </action>

    </package>

</struts>

具體操作:
A.jsp

 <ul>
      <li><a href="user/menuhotlist" target="menu">熱銷菜→</a></li>
      <li><a href="user/menulist?menu.type=1" target="menu">招牌菜→</a></li>
      <li><a href="user/menulist?menu.type=2" target="menu">主食區→</a></li>
      <li><a href="user/menulist?menu.type=3" target="menu">小吃區→</a></li>
      <li><a href="user/menulist?menu.type=4" target="menu">飲料區→</a></li>
   </ul>

<div class="con_right">
   <iframe name="menu" src="user/menuhotlist.action" class="iframe_menu"></iframe>
</div>

B.jsp

 <table cellspacing="0px" style="width:795px; border-collapse:collapse; text-align:center;">
  <%
        Menu menu = null;
        List list = new ArrayList();
        list = (List)session.getAttribute("menuindex");
        String str;
        int i;
        for(i=0;i<list.size();i++){
           menu = (Menu)list.get(i);
  %>
     <tr>
        <td style="width:150px; height:160px; border-bottom:2px dashed #ccc; padding-top:5px; padding-bottom:5px;"><img src="<%=menu.getPic()%>" style="width:150px; height:150px;" ></td>
        <td style="width:295px; border-bottom:2px dashed #ccc; font-size:24px;"><%=menu.getName()%></td>
        <td style="border-bottom:2px dashed #ccc; font-size:24px;">¥<%=menu.getPrice()%></td>
        <td style="border-bottom:2px dashed #ccc; font-size:24px;"><%=menu.getSale()%>&nbsp;份</td>
        <td style="width:170px; border-bottom:2px dashed #ccc;"><input type="button" value="加入購物車" onclick="Button1_onclick(this.id)" style="height:40px; font-size:18px;" /></td>
     </tr>
  <% } %>
  </table>

menuhotlist.action:

 public String menu_list_hot(){
        HttpServletResponse response = ServletActionContext.getResponse();
        Map session = ActionContext.getContext().getSession();
        DBConnect db=new DBConnect();
        Connection con=db.getCon();
        Statement stat = null;
        ResultSet rs = null;
        String sql = "select top 10 m_name,m_price,m_pic,m_sale from menus order by m_sale desc";
        List<Menu> list = new ArrayList();
        try {
            stat = con.createStatement();
            rs=stat.executeQuery(sql);
            while(rs.next()){
                menu = new Menu();
                menu.setName(rs.getString("m_name"));
                menu.setPrice(Float.parseFloat(rs.getString("m_price")));
                menu.setPic(rs.getString("m_pic"));
                menu.setPic(rs.getString("m_sale"));
                list.add(menu);
            }
            con.close();
            //放到session
            session.put("menuindex",list);
            //request.getRequestDispatcher("../index_menu.jsp").forward(request,response);
            //response.sendRedirect("../index_menu.jsp");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "redirect";
    }

menulist.action

 public String menu_list(){
        HttpServletResponse response = ServletActionContext.getResponse();
        Map session = ActionContext.getContext().getSession();
        DBConnect db=new DBConnect();
        Connection con=db.getCon();
        PreparedStatement prepstmt = null;
        ResultSet rs = null;
        String typestr = "";
        String sql = "select m_name,m_price,m_pic,m_sale from menus where m_type = ?";
        List<Menu> list = new ArrayList();
        switch(menu.getType()){
           case 1:typestr="招牌";break;
           case 2:typestr="主食";break;
           case 3:typestr="小吃";break;
           case 4:typestr="飲料";break;
           default:
        }
        try {
            prepstmt = con.prepareStatement(sql);
            prepstmt.setString(1, typestr);
            rs = prepstmt.executeQuery();
            while(rs.next()){
                menu = new Menu();
                menu.setName(rs.getString("m_name"));
                menu.setPrice(Float.parseFloat(rs.getString("m_price")));
                menu.setPic(rs.getString("m_pic"));
                menu.setPic(rs.getString("m_sale"));
                list.add(menu);
                System.out.println(rs.getString("m_pic"));
            }
            con.close();
            //放到session
            session.put("menuindex",list);
            //request.getRequestDispatcher("../index_menu.jsp").forward(request,response);
            //response.sendRedirect("../index_menu.jsp");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "redirect";
    }

A.jsp請求action,action把結果放入session的一個List裡,B.jsp再取出

最佳回答:


如果路徑沒錯的話,可以重新部署下項目或是在struts.xml中添加input視圖試試

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved