1、需要在需要新建一个HTML页面,在页面中引入下面的script标签,这里引用的是开发版本,带有报错提示,便利查找错误。
2、新建一个script标签,newVue实例。
3、上个小demo,点击按钮显示a链接。
给你一个小例子看看就明白了。获取用户输入参数,然后进行数据库查询,查询成功则登录成功12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
public class HandleLogin extends HttpServlet{private String backNews = "" //登录状态返回信息 public void init(ServletConfig config) throws ServletException{super.init(config) } public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{request.setCharacterEncoding("utf-8") response.setCharacterEncoding("utf-8") Login loginBean = null //JavaBeanHttpSession session = request.getSession(true) try {loginBean = (Login) session.getAttribute("login") if(loginBean == null){loginBean = new Login() session.setAttribute("login", loginBean) }} catch (Exception e) {loginBean = new Login() session.setAttribute("login", loginBean) } String id = request.getParameter("id").trim() String password = request.getParameter("password").trim() boolean loginOk = loginBean.isLoginSuccess()if(loginOk&&(id.equals(loginBean.getId())&&(password.equals(loginBean.getPassword())) )){backNews = "尊敬的会员:"+id+",您已经登录,无需重复登录!" loginBean.setBackNews(backNews) }else{boolean chkLength = id.length()>0 &&password.length()>0 //判断用户名和密码是否为空if(chkLength){//连接数据库进行查询验证登录是否正确Connection connection = DbConn.getConnection() try {PreparedStatement pStatement = connection.prepareStatement("select id from member where id=? and password =?") pStatement.setString(1, id) pStatement.setString(2, password) ResultSet resultSet = pStatement.executeQuery()if(resultSet.next()){backNews = "登录成功" loginBean.setId(id) loginBean.setPassword(password) loginBean.setLoginSuccess(true) loginBean.setBackNews(backNews) }else{backNews = "您输入的用户名不存在,或密码不匹配" loginBean.setId(id) loginBean.setLoginSuccess(false) loginBean.setBackNews(backNews) }connection.close() } catch (SQLException e) {backNews = "您输入的用户名不存在,或密码不匹配" loginBean.setId(id) loginBean.setLoginSuccess(false) loginBean.setBackNews(backNews) } }else{backNews = "用户名和密码不能为空" loginBean.setId(id) loginBean.setLoginSuccess(false) loginBean.setBackNews(backNews) }} RequestDispatcher dispatcher = request.getRequestDispatcher("showLoginMess.jsp") dispatcher.forward(request, response) } public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{doPost(request, response) }}
代码挺粗糙的,大概意思就这样的,将就着看吧
1、document.getElementById("txt_"+i).innerHTML = rsArr[i]2、
document.getElementById("txt_"+1).innerHTML = rsArr[0]
document.getElementById("txt_"+2).innerHTML = rsArr[1]
document.getElementById("txt_"+3).innerHTML = rsArr[2]
document.getElementById("txt_"+4).innerHTML = rsArr[3]
发现下标不对应了吗?