当我的控制器将它传递给视图时,数据不会在属性中创建

问题描述 投票:0回答:0
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
    Ask1v1Dao dao = Ask1v1Dao.getInstance();


    
    List<Ask1v1Vo> list = dao.selectAll();
    System.out.println("list size: " + list.size());
    request.setAttribute("list", list);
    request.setAttribute("test", "This is a test attribute");

    RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
    dispatcher.forward(request, response);
}

这是我的控制器

我们测试了dao方法没有问题

            <div><c:out value="${vo.ino }"/>
            <c:out value="${vo.icategory }"/>
            <c:out value="${vo.iaskcategory }"/>
            <c:out value="${vo.icontent }"/>
            <c:out value="${vo.mid }"/>
            <c:out value="${vo.icheck }"/>
            <c:out value="${vo.idate }"/>
                            
            </div>
            
            <ul>
            
            <li>${vo.ino }</li>
                <li>${vo.icategory }</li>
                    <li>${vo.iaskcategory }</li>
                        <li>${vo.icontent }</li>
                            <li>${vo.icheck }</li>
                                <li>${vo.idate }</li>
                                    <li>${vo.ino }</li>
                                    
            </ul>



public static void init() {

    
    mapping.put(new RequestKeyValue("/ask1v1", "GET"), new Ask1v1ViewController());
    mapping.put(new RequestKeyValue("/ask1v1/write", "POST"), new Ask1v1WriteController());
    mapping.put(new RequestKeyValue("/ask1v1/delete", "POST"), new Ask1v1DeleteController());
    mapping.put(new RequestKeyValue("/ask1v1/update", "POST"), new Ask1v1UpdateController());

    
    
    
    
    
    
    
    

}
//url,method 필드를 저장하는 key 를 전달받아 HashMap에서 value(컨트롤러)를 리턴
public static Controller getController(RequestKeyValue key) {
    return mapping.get(key);
}

// getters and setters for the 'url' and 'method' fields

@Override
public void init() throws ServletException {
    RequestControllerMapping.init();
}

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException {   //Get,Post 방식 둘다 처리
    String url = request.getServletPath();
    String method = request.getMethod();
    
    RequestKeyValue key = new RequestKeyValue(url, method);
    Controller controller = RequestControllerMapping.getController(key);

    
    if(controller != null) { 
        logger.info("::::::::::{}-{}::::::::::",key,controller.getClass());
        controller.handle(request, response);
    }
    else { throw new RuntimeException(); }
    //else 는 debuging 완료되면 error 페이지로 구현.
    
}
A列 B列
细胞 细胞 2
细胞 3 细胞 4

your text

  1. 与 db 的连接测试 = 成功

  2. 直接执行dao方法=成功insert语句直接进入db

  3. xml文件路径设置=用mybatis/ask1v1.xml设置正常路径

4.url和方法映射=上面的源码

纠错了3天,实在想不出办法,所以求教。请帮助。

xml jsp jstl
© www.soinside.com 2019 - 2024. All rights reserved.