jsp中java代码可以写在js中吗
答:jsp中java代码可以写在js中。
示例如下:
<script type="text/javascript">
function check(){
var username=document.getElementById("username");
var username=document.getElementById("password");
//java代码块
<%
String sql="select * from Manger";
String user;
String pass;
ResultSet rs=DBHelper.query(sql);//sql代码已经写好在被的类中,此处为直接调用!!
while(rs.next()){
user=rs.getString("username");
pass=rs.getString("password");%>
if(username.value=="<%=user %>" &&passsword.value=="<%=pass%>")
{
return true;
}else if(username.value==""|| password.value==""){
username.setCustomValidity("账号或密码不能为空");
return false;
}else{
username.setCustomValidity("账号或密码错误,请从新输入");
return false;
}
<%
}
%>
}
</script>
function check(){
var username=document.getElementById("username");
var username=document.getElementById("password");
//java代码块
<%
String sql="select * from Manger";
String user;
String pass;
ResultSet rs=DBHelper.query(sql);//sql代码已经写好在被的类中,此处为直接调用!!
while(rs.next()){
user=rs.getString("username");
pass=rs.getString("password");%>
if(username.value=="<%=user %>" &&passsword.value=="<%=pass%>")
{
return true;
}else if(username.value==""|| password.value==""){
username.setCustomValidity("账号或密码不能为空");
return false;
}else{
username.setCustomValidity("账号或密码错误,请从新输入");
return false;
}
<%
}
%>
}
</script>