如果要将引导验证程序生成的远程信息发送到@WebServlet(name =“ check”),该怎么办?
@WebServlet(name="check")
public class IdCheck extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
PrintWriter out = response.getWriter();
JSONObject json = new JSONObject();
String id = request.getParameter("id");
System.out.println(id);
String SQL = "SELECT id FROM USER WHERE id='" + id + "'";
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
conn = DriverManager.getConnection(url, user, pass);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Statement st;
ResultSet rs;
try {
st = conn.createStatement();
rs = st.executeQuery(SQL);
if (rs.next()) {
out.print("{\"valid\" : false }");
json.put("valid", false);
System.out.println("false");
} else {
out.print("{\"valid\" : true }");
json.put("valid", true);
System.out.println("true");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
out.close();
}
}
}
id : {
validators : {
stringLength : {
min : 2,
},
notEmpty : {
message : 'Please enter your id'
},
remote: {
type:'POST',
url: 'check',
delay: 1000,
message: 'ID is already available'
}
}
},
我想将bootstrapvalidator的ID信息发送给“检查”,但无法传递。 我想通过接受bootstrapvalidator作为WebServlet来完成ID检查。