Javascript 如何将数组数据从java发送到jsp,并在jsp中将数据设置为变量?
这是JAVAJavascript 如何将数组数据从java发送到jsp,并在jsp中将数据设置为变量?,javascript,java,arrays,jsp,parameter-passing,Javascript,Java,Arrays,Jsp,Parameter Passing,这是JAVA public class Dest_id extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { String destination = request.getParameter("destination"); String
public class Dest_id extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
String destination = request.getParameter("destination");
String product = request.getParameter("product");
String currency = request.getParameter("currency");
String destQuery = "DESTINATION LIKE '" + destination + "%'";
String prodQuery = "PRODUCT = '" + product + "'";
String currQuery = "MOST_INFL_CURRENCY = '" + currency + "'";
if (destination != null)
destination = destination.toUpperCase();
ResultSet rs;
int bil = 1;
String destID[] = null;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bababa","root","");
Statement stmt = con.createStatement();
rs = stmt.executeQuery("select * from icx_pricing_desk where " + destQuery.toUpperCase() + " AND " + currQuery + " AND " + prodQuery);
while (rs.next()) {
System.out.println(bil + "|" + rs.getString("DESTINATION") + "|" + rs.getString("PRODUCT") + "|" + rs.getString("MOST_INFL_CURRENCY"));
destID[bil] = rs.getString("DEST_ID");
bil++;
}
con.close();
} catch(Exception e) { System.out.println(e); }
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println(destID);
}
}
这是我的JSP页面
<body>
<h1>Pricing Index</h1>
<br>
<div id="main_search">
<form name="m_search" method="GET" action="../../Dest_id" id="m_search">
<table class="searchTable" cellpadding="10" cellspacing="2" border="0" width="100%">
<tr>
<td rowspan="3" valign="top">Product</td><td rowspan="3" valign="top">:</td>
<td rowspan="3" valign="top">
<input type="checkbox" name="product" class="prod_checkbx" value="Bilateral-VC">Bilateral-VC<br>
<input type="checkbox" name="product" class="prod_checkbx" value="Bilateral Non-VC">Bilateral Non-VC<br>
<input type="checkbox" name="product" class="prod_checkbx" value="Budget Domestic">Budget Domestic<br>
<input type="checkbox" name="product" class="prod_checkbx" value="Budget High">Budget High<br>
<input type="checkbox" name="product" class="prod_checkbx" value="Budget International">Budget International<br>
</td>
</tr>
<tr>
<td valign="top">Destination</td>
<td valign="top">:</td>
<td valign="top"><input id="destination" type="text" style="text-transform: uppercase;" name="destination"/></td>
</tr>
<tr>
<td valign="top">Currency</td>
<td valign="top">:</td>
<td valign="top">
<select id="currency" name="currency">
<option value="RM">RM</option>
<option value="SDR">SDR</option>
<option value="USD">USD</option>
</select>
</td>
</tr>
<tr>
<td colspan="9" align="center">
<input type="submit" value="SeArCh" id="search" name="search" class="button orange small" style="cursor:pointer;"/>
</td>
<td><a href="#" type="submit" name="submit" id="submit" onclick="document.form1.submit()">lol</a></td>
</tr>
</table>
</form>
</div>
<script type="text/javascript">
var form = $('#m_search');
form.submit(function () {
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
var result=data;
//$('#result').attr("value",result);
$('#result').html(result);
}
});
return false;
});
</script>
<div id="search_crit">
<table class="searchTable" cellpadding="10" cellspacing="2" border="0" width="100%">
<tr><td></td></tr>
</table>
</div>
<div id="search_result" style="overflow: auto;">
<h2>Floor Price Edit</h2>
<div id="result"></div>
<br />
嗯。。。大多是这样。但是如果您有更好的想法,请帮助。我想实际上它是以字符串的形式出现的,请尝试使用JSON并将响应设置为JSON,或者在JAVASCRIPT中通过JSON.parse(“yourResponseData”)将其转换为JSON;实际上,我想它是以字符串的形式出现的,试着使用JSON并将响应设置为JSON,或者在JAVASCRIPT中通过JSON.parse(“yourResponseData”)转换它;
<sql:query var="dest_result" dataSource="${db}">SELECT * from table WHERE DEST_ID = '<div id="result"></div>'</sql:query>
<c:forEach var="row" items="${dest_result.rows}">
<tr bgcolor="#DEB887">
<td><c:out value="${row.DEST_ID}"/></td>
<td><c:out value="${row.DESTINATION}"/></td>
<td><c:out value="${row.PRODUCT}"/></td>
<td><c:out value="${row.MOST_INFL_CURRENCY}"/></td>
</tr>
</c:forEach>