小编典典
您不能在JSP的if语句中调用JavaScript函数,因为JSP在服务器端执行,而JavaScript在客户端执行。
单击单选按钮之一时必须触发事件,使用onclick事件可以调用function corc()。
不要在JSP中编写scriptlet,因为scriptlet在JSP中不应使用超过十年。学习JSPEL和JSTL,并将servlet用于Java代码。
JSP代码:
.......
........
//use
to submit values to servlet......
.......
//use hidden field to assign table value i.e. "customer" or "company".
//
closing form tagonclick事件我分配了handleClick函数并传递了this.id参数this.id,用于传递id单击的单选按钮的属性。
JavaScript代码:
function handleClick(clickedId)
{
if(clickedId == "customerId")
document.getElementById('tableTextId').value = "customer";
else
document.getElementById('tableTextId').value = "company";
}
当您提交表单然后在servlet中时,您可以获得隐藏字段的值。
字符串tableName = request.getParameter(“ tableValue”); //传递隐藏字段的名称,即tableValue
您可以进一步将其传递tableName给查询。
2020-06-08