package com.mage.test;
import java.io.IOException;
import javafx.scene.paint.Color;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class ServletLogin
* @param <setTextColor>
*/
@WebServlet("/Login")
public class ServletLogin<setTextColor> extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//解决乱码
resp.setContentType("text/html;charset=UTF-8");
//接受参数
String uname = req.getParameter("uname");
String upwd = req.getParameter("upwd");
//判断
if("root".equals(uname) && "root".equals(upwd)){
resp.getWriter().write("<font color='green'>"+"欢迎 "+uname+" login!!!");
resp.getWriter().write("</font>");
}else{
resp.getWriter().write("<font color='red'>"+"用户名或密码错误!!!");
resp.getWriter().write("</font>");
}
resp.getWriter().flush();
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="Login" align="center">
用户:<input type="text" name="uname" value="root"><br/>
密码:<input type="text" name="upwd" value="root"><br/>
<input type="submit" value="提交">
</form>
</body>
</html>
//用户密码默认是root