Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在jsp代码中编写td。我已经写了结果,但是合并了 在此处插入标题 问题 正确答案 答卷_Java_Jsp_Jdbc - Fatal编程技术网

Java 如何在jsp代码中编写td。我已经写了结果,但是合并了 在此处插入标题 问题 正确答案 答卷

Java 如何在jsp代码中编写td。我已经写了结果,但是合并了 在此处插入标题 问题 正确答案 答卷,java,jsp,jdbc,Java,Jsp,Jdbc,问题是您的表html没有很好地嵌套在循环中 <%@page import="java.util.List"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/

问题是您的表html没有很好地嵌套在循环中

<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
        <%@ page import="java.sql.*" %>
        <%@ page import= "myExam.quest" %>
    </head>
    <body>
        <%! int index=0; %> 
        <%! int pos=0; %>   

        <% String c,a;
            String[] CA =(String[])session.getAttribute("CA");
            String[] AS =(String[])session.getAttribute("AS");
            List<quest> l=(List<quest>)session.getAttribute("myquestion");
            quest[] question = new quest[l.size()];
            l.toArray(question);
        %>
        <table border=1>
            <tr>
                <th  colspan="2" width="500">Questions</th>
                <th>CorrectAnswer</th>
                <th>Answer sheet</th>
            </tr>
            <tr>
                <% 
                    for(pos=0;pos<question.length;pos++){
                    String ques=question[pos].ques;
                    String opa=question[pos].opa;
                    String opb=question[pos].opb;
                    String opc=question[pos].opc;
                    String opd=question[pos].opd;
                    c=CA[pos];
                    a=AS[pos];
                %>  
                <td>Question <%=pos+1%></td>
                <td width="500"><%= ques %></td>
                <td><%=c  %></td>
                <td><%= a%>
            </tr>
        </table>
        <%} %>
    </body>
</html>


使用脚本来编写代码是一个非常糟糕的做法。你应该避免使用涂鸦。无论如何,请尝试以下代码:

在此处插入标题

问题
正确答案
答卷

你所做的是完全错误的。必须避免使用scriptlet。这是一种糟糕的编程实践。请尝试编写您至少能理解的代码。整齐地格式化代码,以了解是否遗漏了任何标记。@dhananjaykumar下面的答案解决了您的问题吗?@Perry您说过避免sciplet,因为我在jsp上使用的是Java服务器页面标准标记库(JSTL)和表达式语言(EL),我添加了遗漏的标记,同时也为循环移动内部,谢谢,但输出仍然是一样的。你肯定又犯了一些错误@dhananjaykumar。只需在
jsp
中替换此代码即可。这应该是有效的。@KrishnaKuntala,请告诉我你的解决方案和我的帖子有什么不同?我已经努力先格式化这段代码并回答了它。这可能不是一个不同的解决方案,但它不是你文章的副本。所以不要担心@Arvind:-)Thanks@KrishnaKuntala它起作用了。今天我已经试过了。非常感谢两人you@dhananjaykumar,我请求您更新您的帖子,不要覆盖现有的帖子,只需将新代码复制粘贴到旧代码的正下方,标题为Edited:。我猜相关部分是
,这就足够了。@Arvind该问题已由我编辑,并由SFO社区成员接受,其格式应为可读格式。这与dhananjay kumar提出的问题相同,但格式可读。
 <% 
 for(pos=0;pos<question.length;pos++){
 String ques=question[pos].ques;
 String opa=question[pos].opa;
 String opb=question[pos].opb;
 String opc=question[pos].opc;
 String opd=question[pos].opd;
 c=CA[pos];
 a=AS[pos];
%>
   <tr> <!-- moved inside -->
    <td>Question <%=pos+1%></td>
    <td width="500"><%=ques%></td>
    <td><%=c%></td>
    <td><%=a%></td> <!-- added missing closing tag -->
   </tr>
<%} %>
</table><!-- moved outside -->
    <% String c,a;
        String[] CA =(String[])session.getAttribute("CA");
        String[] AS =(String[])session.getAttribute("AS");
        List<quest> l=(List<quest>)session.getAttribute("myquestion");
        quest[] question = new quest[l.size()];
        l.toArray(question);
    %>
    <table border=1>
        <tr>
            <th  colspan="2" width="500">Questions</th>
            <th>CorrectAnswer</th>
            <th>Answer sheet</th>
        </tr>
        <% 
            for(pos=0;pos<question.length;pos++){
            String ques=question[pos].ques;
            String opa=question[pos].opa;
            String opb=question[pos].opb;
            String opc=question[pos].opc;
            String opd=question[pos].opd;
            c=CA[pos];
            a=AS[pos];
        %>
            <tr><!-- moved tr inside for loop-->
                <td>Question <%=pos+1%></td>
                <td width="500"><%= ques %></td>
                <td><%=c  %></td>
                <td><%= a%></td><!-- added missing /td-->
            </tr>
        <%} %>
    </table><!-- moved /table outside of for loop-->
</body>