</pre><h3>这只是MyEclipse加TomCat进行简单的验证,在login页面输入用户名和密码进行验证。</h3><pre name="code" class="java">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 ServletOne extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//通知客户端以utf-8编码进行解析
resp.setContentType("text/html;charset=utf-8");
//数据库以UTF-8编码解析数据
req.setCharacterEncoding("UTF-8");
//获取数据
String username = req.getParameter("username");
String password = req.getParameter("password");
//验证用户名和密码
PrintWriter writer = resp.getWriter();
System.out.println(username+"------------"+password);
if(username.trim().equals("kylin") && password.equals("kylin")){
writer.write("登录成功");
}else{
writer.write("验证失败");
}
}
}
JAVA Web简单的用户名密码验证
最新推荐文章于 2024-09-24 16:44:58 发布