Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Myeclipse use tool to achieve the correct account js expression input box jump page code
- Ready index.jsp show.jsp java code as well as the following code:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style>
</style>
</head>
<body>
<form>
账号:<input type="text" name="name" id="name"><br/>
密码:<input type="text" name="pwd" id="pwd"><br/>
<input type="button" value="登录"/>
<script type="text/javascript"></script>
<script>
$(function(){
$(":button").on("click",function(){
$.ajax({
type:"GET",
url:"test",
data:{
name:$("#name").val(),
pwd:1
},
dataType:"text",
success:function(data){
if(data=="ok"){
// window.location.href="show.jsp";
alert("登录成功");
}else{
// $("#show").text("登录失败!");
alert("登录失败");
}
}
})
})
});
</script>
</form>
</body>
</html>
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 GengTenrr extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException ,IOException{
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter out =response.getWriter();
String name ="小明";
String pwd="11111";
String ajaxName=request.getParameter("name");
String ajaxpwd=request.getParameter("pwd");
System.out.println(ajaxName+":"+ajaxpwd);
if(name.equals(ajaxName)&&pwd.equals(ajaxpwd)){
out.print("111");
}else{
out.print("error");
}
out.flush();
out.close();
}
}
- The following effects: