JSP<form action="SearchSQuestion" method="post">
<table align="center">
<tr>
<td><label>題目?jī)?nèi)容:</label></td>
<td><input name="problem" type="text" value="${problem}"/></td>
<td> </td>
<td><label>答案:</label></td>
<td><input name="answer" type="text" value="${answer}"/></td>
<td> </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>();Servletprotected 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);
}servicepublic List<Schoice> querySchoiceList(String problem, String answer) {
SQuestionDao sq = new SQuestionDao();
return sq.SearchSchoice(problem, answer);
}
2 回答

白豬掌柜的
TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊
貼這么一大堆沒(méi)用,且不說(shuō)這里任意一個(gè)地方都可能出錯(cuò),而且數(shù)據(jù)庫(kù)表、配置和用戶的輸入也會(huì)可能導(dǎo)致查詢不出來(lái)。
你得學(xué)會(huì)調(diào)試。
調(diào)試的關(guān)鍵點(diǎn)在于,首先檢查dao的代碼得到的參數(shù)problem answer是否正確傳進(jìn)來(lái)了
try catch丟出什么錯(cuò)誤了,返回值是什么
縮小你的錯(cuò)誤可能發(fā)生位置的范圍,直到找到問(wèn)題。

江戶川亂折騰
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
如果dao傳不進(jìn)去,你dao的代碼可以不用看了,然后看String problem = request.getParameter("problem");等,這里又沒(méi)有傳進(jìn)去
添加回答
舉報(bào)
0/150
提交
取消