为什么我不能从这个表单到达我的servlet?

时间:2014-08-02 05:16:41

标签: javascript jsp servlets html-form scriplets

您不必完成完整的代码。只需查看body标签中的第一个表分配和document.write()。我在一个脚本中使用document.write()创建了完整的页面。在代码的最后,您可以看到在窗体关闭之前有提交按钮。当我运行页面并单击提交按钮时,它不会转到servlet ...这里有什么问题?

<%@page import="s_pack.dbManager"%>
<%@ 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>
</head>
<body>
        <script language = "javascript" type = "text/javascript">

        table = '<form action = "AM2Servlet" method = "get" >'
        document.write(table);
        table = '<select name = "selected_course_id_in_marking">'
        document.write(table);

        var c_id,s_name;
        <%
            String co_id = request.getParameter("course_id_QSParam");
            System.out.println(co_id);
        %>
        c_id = '<%=co_id%>'

        document.write('<option>'+c_id+'</option>');
        table = '</select>'
        document.write(table);

        table = '<select name = "selected_student_in_marking">'
        document.write(table);
        <%
            String due_student_list[] = dbManager.get_students_with_due_result(co_id);
            for(int i=0;i<due_student_list.length;i++)
            {
        %>
                s_name = '<%= due_student_list[i]%>'
                document.write('<option>'+ s_name + '</option>');
        <%
            }
        %>

        table = '</select>'
        document.write(table);
        table = '<table  border="1" cellspacing="1" cellpadding="5">'
        document.write(table);
        <%
            for(int i=1;i<6;i++)
            {
        %>
                temp = '<%=i%>'
                table = '<tr><td> In Course '+temp
                table = table + ' Mark: <select name = "InCourse'+temp+'Mark">'
                document.write(table);
                for(var mark=0; mark<=30;mark=mark+.5)
                {
                    document.write("<option>"+mark+"</option>");
                }
                document.write('</select></tr>');
        <%
            }
        %>

        <%
            for(int i=1;i<2;i++)
            {
        %>
                temp = '<%=i%>'
                table = '<tr><td> Assignment '
                table = table + 'Mark: <select name = "Assignment'+temp+'Mark">'
                document.write(table);
                for(var mark=0; mark<=10;mark=mark+.5)
                {
                    document.write("<option>"+mark+"</option>");
                }
                document.write('</select></tr>');
        <%
            }
        %>

        <%
            for(int i=1;i<2;i++)
            {
        %>
                temp = '<%=i%>'
                table = '<tr><td> Project '
                table = table + 'Mark: <select name = "Project'+temp+'Mark">'
                document.write(table);
                for(var mark=0; mark<=40;mark=mark+.5)
                {
                    document.write("<option>"+mark+"</option>");
                }
                document.write('</select></tr>');
        <%
            }
        %>

        <%
            for(int i=1;i<2;i++)
            {
        %>
                temp = '<%=i%>'
                table = '<tr><td> Lab '
                table = table + 'Mark: <select name = "Lab'+temp+'Mark">'
                document.write(table);
                for(var mark=0; mark<=60;mark=mark+.5)
                {
                    document.write("<option>"+mark+"</option>");
                }
                document.write('</select></tr>');
        <%
            }
        %>

        <%
            for(int i=1;i<3;i++)
            {
        %>
                temp = '<%=i%>'
                table = '<tr><td> Viva '+temp
                table = table + ' Mark: <select name = "Viva'+temp+'Mark">'
                document.write(table);
                for(var mark=0; mark<=10;mark=mark+.5)
                {
                    document.write("<option>"+mark+"</option>");
                }
                document.write('</select></tr>');
        <%
            }
        %>

        <%
    for(int i=1;i<2;i++)
    {
%>
    temp = '<%=i%>'
    table = '<tr><td> Attendance '
    table = table + 'Mark: <select name = "Attendance'+temp+'Mark">'
    document.write(table);
    for(var mark=0; mark<=10;mark=mark+.5)
    {
        document.write("<option>"+mark+"</option>");
    }
    document.write('</select></tr>');
<%
    }
%>

<%
    for(int i=1;i<2;i++)
    {
%>
    temp = '<%=i%>'
    table = '<tr><td> Semester Final '
    table = table + 'Mark: <select name = "SemesterFinal'+temp+'Mark">'
    document.write(table);
    for(var mark=0; mark<=60;mark=mark+.5)
    {
        document.write("<option>"+mark+"</option>");
    }
    document.write('</select></tr>');
<%
    }
%>
        table = '</table></form>'
        document.write(table);

 table = '<hr> </br></br>'
 table = table + '<h1> Additional Exams </h1> <hr>'
 document.write(table);
 table = 'Name of Exam: <input type = "text" name="AdditionalExam1">  Obtained Mark:'
 document.write(table);
 table = '<select name = "AdditionalExam1Mark">'
 document.write(table);
 for(var mark=0; mark<=100;mark=mark+.5)
 {
    document.write("<option>"+mark+"</option>");
 }
 document.write('</select>');

 table = 'Name of Exam: <input type = "text" name="AdditionalExam2">  Obtained Mark:'
 document.write(table);
 table = '<select name = "AdditionalExam2Mark">'
 document.write(table);
 for(var mark=0; mark<=100;mark=mark+.5)
 {
    document.write("<option>"+mark+"</option>");
 }
 document.write('</select>');
 table = '<input type="submit" value="Assign Marks"></form>'
 document.write(table);

 </script>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

关闭表单时出错。关闭它两次..