运用Ajax实现登陆并且跳转页面

在这里插入图片描述

css样式


设置两个输入框和一个button登录按钮

"post"> "text" required="required" placeholder="用户名" name="name" id="name" οnblur="check_name()">"nameReg"> "password" required="required" placeholder="密码" name="pwd" id="pwd" οnblur="check_pwd()">"pwdReg">

js(正则表达式)+jquery判断登陆是否成功

 

登陆成功后的jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

"-//W3C//DTD HTML 4.01 Transitional//EN">

  
    "<%=basePath%>">
    
    My JSP <span class="token string">'index.jsp'</span> starting page
    
	"pragma" content="no-cache">
	"cache-control" content="no-cache">
	"expires" content="0">    
	"keywords" content="keyword1,keyword2,keyword3">
	"description" content="This is my page">
	

  
  
  
   

这是登录成功后才跳转到的页面!


Ajax(url)的调用

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AjaxServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		//用户名登录
		String name = "admin";
		//密码登录
		String pwd = "521789";
		
		String nameAjax = request.getParameter("name");
		String pwdAjax = request.getParameter("pwd");
		if (name.equals(nameAjax) && pwd.equals(pwdAjax)) {
		//验证/判断
			out.print("ok");
		}else{
			out.print("error");
		}
		out.flush();
		out.close();
	}
}

你可能感兴趣的:(js+css,JQuery)