http://bbs.itheima.com/thread-16465-1-1.html
能解决问题的奉上金钱30
这是上一个问题的链接 我已经解决了一半
我把每一个选项 通过 ajax 用HashMap存起来
但是不晓得是我没能存储成功,还是我取的时候有问题,就是显示空指针
现在把问题贴出来 各位高手帮忙看看
这是选择题答题页面- <%
- request.setCharacterEncoding("utf-8");
- PageBean pageBean=new PageBean();
- String condition=(String)session.getAttribute("condition");
- session.removeAttribute("condition");
- if(condition==null)
- {
- condition="";
- }
- int pageNum=2;
- int currPage;
- String url="exam_1.jsp";
- if(request.getParameter("pages")==null)
- {
- currPage=0;
- }
- else
- {
- currPage=new Integer(request.getParameter("pages")).intValue();
- }
- System.out.println("here is currPage!");
- pageBean.setCondition(condition);
- pageBean.setCurrPage(currPage);
- pageBean.setPageNum(pageNum);
- session.setAttribute("pageBean", pageBean);
- Map map = null;
- if(session.getAttribute("test") != null)
- {
- map = (Map)session.getAttribute("test");
- }
- Convert con=new Convert();
- String t_type=(String)session.getAttribute("t_type");
- QuestionDO qus=new QuestionDO();
- List<QuestionInfo> list=qus.findQuestion(pageBean);
- int start=currPage*pageNum;
- int end=start+pageNum;
- if(list!=null && list.size()>0)
- {
- for(int i=start;i<end;i++)
- {
- QuestionInfo info=new QuestionInfo();
- info=list.get(i);
- %>
- <p>第<%= info.getId()%>题. <%= con.toGbk(info.getQuestion())%>()
-
- A.<input type="radio" name="t<%=info.getId()%>" value='a' <%= QuestionUtil.getResultByQid(map,info.getId().toString(), "a") %>> <%= con.toGbk(info.getAs1())%>
- B.<input type="radio" name="t<%=info.getId()%>" value='b' <%= QuestionUtil.getResultByQid(map,info.getId().toString(), "b") %>> <%=con.toGbk(info.getAs2())%>
- C.<input type="radio" name="t<%=info.getId()%>" value='c' <%= QuestionUtil.getResultByQid(map,info.getId().toString(), "c") %>> <%=con.toGbk(info.getAs3())%>
- D.<input type="radio" name="t<%=info.getId()%>" value='d' <%= QuestionUtil.getResultByQid(map,info.getId().toString(), "d") %>> <%=con.toGbk(info.getAs4())%>
- <%
- }
- }
- %>
- <p align="center">
- <%=Pagination.getPaginationScript(pageBean.getCurrPage(), pageBean.getPageNum(), pageBean.getRecordNum(), pageBean.getCondition(), url) %>
- <p><input type="submit" value="提交答案">
- </form>
- </div>
- </body>
- <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
- <script type="text/javascript">
- $(function(){
- $("input[type=radio]").click(function(){
- //alert("题号:" + $(this).attr("name") + "答案:" + $(this).val());
- var qid = $(this).attr("name");
- var correct = $(this).val();
- //提交状态
- $("#s"+qid).html("loading");
- $.post("ajax/questionSubmit.jsp?qid="+qid + "&correct="+correct,function(date,state){
- if(state == "success"){
- $("#s"+qid).html("ok");
- //alert(date);
- }
- else{
- alert("网络繁忙请稍候重试!错误信息"+state);
- }
- });
- });
- });
- </script>
复制代码 以下是ajax页面- <%
- Long qid=Long.parseLong(request.getParameter("qid"));
- String correct=request.getParameter("correct");
- QuestionInfo q=new QuestionInfo();
- q.setId(qid);
- q.setCorrect(correct);
- if(session.getAttribute("test")==null)
- {
- Map map=new HashMap();
- map.put(qid, q); //键——值
- session.setAttribute("test", map);
- }
- else
- {
- Map map=(Map)session.getAttribute("test");
- map.put(qid, q);
- session.setAttribute("test", map);
- }
- %>
复制代码 答题页面会提交到result.jsp
请问在这里该怎么取值呢???我要在这个页面与数据库对比答案并给出得分
|