提交内部文本位于xmlHttp.responseText中的表单

时间:2012-10-11 12:46:44

标签: javascript jquery ajax jsp struts

我已经制作了一个struts应用程序。 前页是jsp,它有一个表单和一个图像。 如果在字段中输入任何数据并单击图像,它将搜索该特定值的详细信息并将其打印在同一页面上的div中。 返回的数据采用表格的形式,带有复选框和值。此表格式位于另一个jsp页面中。 我使用Ajax来获取所有值并将其显示在同一页面上,因此我无需一直刷新。

`document.getElementById("prtCnt").innerHTML=xmlhttp.responseText;`


where "prnCnt" is the Id of that div.

现在我想检查一些复选框并提交整个表单(表单上已有的字段和带复选框的表值)。

我应该怎么做?

abc.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
   <%@taglib uri="/WEB-INF/struts-html" prefix="html"%>
<!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>
<script src="ajaxjs.js"></script>
</head>
<script>
function getvalue() {
    var value = document.getElementById("client").value;
    loadContent(value);
}
</script>
<body>
<html:form action="AjaxAction.do" >
    <html:text property="client"  value="ankit"  styleId="client" /> <img
        style="cursor: hand" id="search" src="images/1search.gif"  width="15"
        height="15" border="0" onclick="getvalue()">
     </html:form>
 <div id="prtCnt"></div>
 </body>

</html>`

ajaxjs.js

var xmlhttp; function loadContent(value) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support Ajax HTTP"); return; } url="AjaxAction.do?client="+value; xmlhttp.onreadystatechange=getOutput; xmlhttp.open("post",url,true); xmlhttp.send(null); } function getOutput() { if (xmlhttp.readyState==4) { alert(xmlhttp.responseText); document.getElementById("prtCnt").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null; }

tableshow.jsp

enter code here

<%@page import="com.ajax.AjaxForm"%>
<%
AjaxForm aj = (AjaxForm) request.getAttribute("bean");
%>
<html>
<body>
<table width="99%" border="1" cellspacing="0" cellpadding="0">
<tr align="left" class="tableheader">
<td width="5%">CheckBox</td>
    <td width="10%">Account Number</td>
    <td width="12%">Tax Form ID</td>
    <td width="12%">Account Name</td>
    <td width="12%">Product</td>
    <td width="12%">Bank ID</td>
    <td width="12%">Client ID [ECI]</td>
    <td width="10%">Relationship type</td>
    <td width="5%">LOB</td>
    <td width="10%">Account Status</td>
</tr>
<tr class="GridRow">
<td width="5%"><input type="checkbox" name="check"> </td>
    <td width="10%"><a href=""><%=aj.getDummy()%></a>
    </td>
    <td width="12%"><%=aj.getClient()%></td>
    <td width="12%"><%=aj.getDummy()%></td>
    <td width="12%"><%=aj.getDummy()%></td>
    <td width="12%"><%=aj.getDummy()%></td>
    <td width="12%"><%=aj.getDummy()%></td>
    <td width="10%"><%=aj.getDummy()%></td>
    <td width="5%"><%=aj.getDummy()%></td>
    <td width="10%"><%=aj.getDummy()%></td>
</tr>

</table>
</body>
</html>

`

AjaxAction.java

package com.ajax;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class AjaxAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    System.out.println("from action");
    AjaxForm aj = (AjaxForm) actionForm;
    System.out.println(request.getParameter("client"));
    if(aj.getClient()!=null){}
    else
        aj.setClient("ankit");
    //aj.setClient(request.getParameter("client"));

    System.out.println(aj.getClient()+"1111111111111111111111111111111");
    if (aj.getClient().equals("ankit"))
        aj.setDummy("Dummy Value for ankit");
    else if (aj.getClient().equals("arpit"))
        aj.setDummy("Dummy Value for arpit"); 
    else if (aj.getClient().equals("rohit"))
        aj.setDummy("Dummy Value for rohit");
    else{
        aj.setClient("soni");
        aj.setDummy("Dummy Value for soni");
    }
    System.out.println("after setting");
    System.out.println(aj.getClient());
    System.out.println(aj.getDummy());
    request.setAttribute("bean", aj);
    return mapping.findForward("success");
}
}

0 个答案:

没有答案