帮忙看一下为什么输入查询条件后查询不到信息

JSP

<form action="SearchSQuestion" method="post">
            <table align="center">
                <tr>
                    <td><label>题目内容:</label></td>
                    <td><input name="problem" type="text" value="${problem}"/></td>
                    <td>&nbsp;</td>
                    <td><label>答案:</label></td>
                    <td><input name="answer" type="text" value="${answer}"/></td>
                    <td>&nbsp;</td>
                    <td><button class="btn btn-primary" style="margin-bottom: 8px;" type="submit" >查询</button></td>
                </tr>
            </table>
        </form>

DAO

// 条件查询单选题信息
        public List<Schoice> SearchSchoice(String problem, String answer) {
            ArrayList<Schoice> list = new ArrayList<Schoice>();
            try {
                Class.forName("com.mysql.jdbc.Driver");
                String url = "jdbc:mysql://127.0.0.1:3306/appoi";
                Connection con = DriverManager.getConnection(url, "root", "123348");

                StringBuilder sql = new StringBuilder(
                        "select id,problem,optionA,optionB,optionC,optionD,answer,jointime from s_choice where 1=1 ");
                List<String> paramList = new ArrayList<String>();

Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
         String problem = request.getParameter("problem");
         String answer = request.getParameter("answer");
         request.setAttribute("problem",problem);
         request.setAttribute("answer",answer);
         a list =new a();
         request.setAttribute("sc",list.querySchoiceList(problem, answer));
         request.getRequestDispatcher("/searchsquestion.jsp").forward(request,response);
    }

service

public List<Schoice> querySchoiceList(String problem, String answer) {
        SQuestionDao sq = new SQuestionDao();
        return sq.SearchSchoice(problem, answer);
}


慕森王
浏览 837回答 2
2回答

白猪掌柜的

贴这么一大堆没用,且不说这里任意一个地方都可能出错,而且数据库表、配置和用户的输入也会可能导致查询不出来。你得学会调试。调试的关键点在于,首先检查dao的代码得到的参数problem answer是否正确传进来了try catch丢出什么错误了,返回值是什么缩小你的错误可能发生位置的范围,直到找到问题。

江户川乱折腾

如果dao传不进去,你dao的代码可以不用看了,然后看String problem = request.getParameter("problem");等,这里又没有传进去
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java