2 partyjat PartyJat 于 2016.04.25 12:46 提问

关于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再取出

3个回答

curry_du
curry_du   2016.04.25 15:52
已采纳

如果路径没错的话,可以重新部署下项目或是在struts.xml中添加input视图试试

PartyJat
PartyJat 0.0搞定了,谢谢,原来是名字复制后忘记改了
一年多之前 回复
qq_27556567
qq_27556567   2016.04.25 13:15

你这执行的是什么操作呢 能详细点吗

PartyJat
PartyJat 一个JSP页面通过超链接传参给menulist.action,查询完毕后,把list放到session,再返回另一个页面,那个页面读取session里的list
一年多之前 回复
CSDNXIAOD
CSDNXIAOD   2016.04.25 13:18

struts2的validate在使用过程中的一个问题
struts2的validate在使用过程中的一个问题
struts2 的一个问题
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!