jsp页面问题 - 不显示弹出窗口

时间:2013-11-30 08:46:55

标签: javascript jsp

我的jsp中有如下代码,它决定了我的Admin主页上选中的复选框。我正在使用javascript和java的混合来获取和发布数据。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import = "java.sql.*" import = "controller.LoginServlet"%>

<!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>Administrator Home Page</title>
<script type="text/javascript">

function getCheckedBoxes(chkboxName) 
{
     av = document.getElementsByName("mycheckedbox");
     for (var e=0;e<j;e++) 
     {
      if (av[e].checked==true)
          {
          document.write("Checkbox selected is " + av[e]);
          alert(e + " selected");
          }

     }
}

function redirectUser()
    {
    var req1 = request.getParameter("subAdd");
    var req2 = request.getParameter("subReject");

    var frm = document.forms[0];

    if(req1 != null && req1.equals("Add"))
    {
        var pageName = "/LoginServlet?method=add";
        frm.action = pageName;
        frm.submit();
    }
    if(req2 != null && req2.equals("Reject"))
        {
            var pageName = "/LoginServlet?method=reject";
            frm.action = pageName;
            frm.submit();
        }
    }

</script>
</head>
<body>
<form name="Admin_Home" action="LoginServlet" method="post">
<% 
    String user_name = new String();
    user_name = request.getParameter("user_name");
    %>
<font color="green">Welcome Admin, <% out.println(user_name); %>!!</font>

<table>
<%
int i;
int j = 0;
int count = (Integer)request.getAttribute("count");
String[] first_name = new String[1000];
String[] group_name = new String[1000];
first_name = (String[])request.getAttribute("first_name");
group_name = (String[])request.getAttribute("group_name");
for (i=0; i<count; i++)
{
%>
<tr>
<td><font color="black"><% out.println(first_name[i] + "  " + group_name[i]); %></font>
<input type = 'checkbox' value = <% j++; %> name = 'mycheckedbox'></input>
</td>
</tr>
<%
}
System.out.println("value of i = " + i);
%>


<tr>
<td>
<input type="submit" name="subGetChked" id="subGetChked" value = "Get Checked Checkboxes" onclick="getCheckedBoxes('mycheckedbox')">
<input type="submit" name="subAdd" id="subAdd" value = "Add" onclick="getCheckedBoxes('mycheckedbox')">
<input type="submit" name="subReject" id="subReject" value = "Reject" onclick="getCheckedBoxes('mycheckedbox')">
</td>
</tr>
</table>
</form>
</body>
</html>

当我运行页面时,这不显示选中的复选框警告。你能帮帮我吗?

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

我复制你的代码我改变了一些地方。下面是我的html部分:

<html>
<head>          
 <script type="text/javascript">
    function getCheckedBoxes(chkboxName) {
        var j =0;           
        if (chkboxName.checked==true) {
            //document.write("Checkbox selected is " + av);
            alert(" selected");
        }           
    }

    function redirectUser() {
        ....
    }

</script>
</head>
<body>
  <form name="Admin_Home" action="LoginServlet" method="post">
    <font color="green">Welcome Admin, !!</font>
    <table>
    <tr>
        <td>
            <input type = 'checkbox' value = "25" name = 'mycheckedbox' id="one"></input>
        </td>
    </tr>
    <tr>
        <td>
            <input type="button" name="subGetChked" id="subGetChked" value = "Get Checked Checkboxes" onclick="getCheckedBoxes(Admin_Home.mycheckedbox)">
            <input type="submit" name="subAdd" id="subAdd" value = "Add" onclick="getCheckedBoxes('mycheckedbox')">
            <input type="submit" name="subReject" id="subReject" value = "Reject" onclick=" getCheckedBoxes('mycheckedbox')">
        </td>
    </tr>
</table>
</form>

</body>
</html>

它在我的电脑上工作正常,希望它可以帮到你:D。 还有问题吗?告诉我,我试试。