【发布时间】:2011-07-22 00:02:19
【问题描述】:
我在客户端有以下代码:
<script src="http://code.jquery.com/jquery-1.5.js"></script>
<script>
$(document).ready(function() {
$("a").click(function() {
//var orderId = $("#orderId").val();
$.post("test", { orderId : "John"},
function(data) {
alert("Data Loaded: " + data);
});
});
});
</script>
服务器端:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter writer = response.getWriter();
try{
String orderId = request.getAttribute("orderId").toString();
writer.write(orderId);
writer.close();
}
catch(Exception ex)
{
ex.getStackTrace();
}
}
我的
request.getAttribute("orderId")
为空,我得到空引用异常。我究竟做错了什么?
【问题讨论】:
标签: java ajax json servlets post