【发布时间】:2013-04-27 18:01:14
【问题描述】:
我有一个 jsp,其中我有选择标签,我想得到 以及从我的 Servlet 中的 jsp 中选择的值
<select id="listoffood" name="dropdown" onchange="foodname();">
<option value="bg">Burger</option>
<option value="pas">pasta</option>
<option value="pi">pizza</option>
</select>
<div id='content'></div>
这里是javascript代码
function foodname()
{
var xmlHttpReq = false;
var self = this;
document.getElementById('content').innerHtml='';
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('GET', "InformationServlet", true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.send(null);
self.xmlHttpReq.onreadystatechange= function ()
{
//alert(document.getElementById('content'));
if (self.xmlHttpReq.readyState==4)
{
if (self.xmlHttpReq.status == 200)
{
document.getElementById('content').innerHTML=self.xmlHttpReq.responseText;
}
}
};
}
我所做的是使用这样的获取属性,但它无法正常显示为空
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// TODO Auto-generated method stub
String coun = request.getParameter("dropdown");
PrintWriter out=response.getWriter();
System.out.println("here : "+coun);
}
提前致谢,我们非常感谢您提供任何代码。
【问题讨论】:
-
它会转到同一个 servlet 吗?发布您的完整 html 表单
-
方法
foodName()是做什么的?您的选择在form内吗? -
#kshitj 食物名称转到 javascript 和 js,而不是通过 ajax 调用 servlet。 @Baadshah 是的,它在 onChange 方法上使用相同的 servlet
-
你能在你的servlet中从这个JSP页面获取其他参数吗?
-
我没有任何 html 表单,我的 jsp 上只有一个选择标签 @AnkitSingla 我的 jsp 上没有其他参数,只有选择标签