文件名称:JAVA WEB 开发详解(JSP+Serlet)
文件大小:1.74MB
文件格式:RAR
更新时间:2012-04-02 16:23:51
JSP Serlet JAVA
package org.sunxin.lesson.jsp.ch24; import javax.servlet.*; import java.io.*; import javax.servlet.http.*; public class LoginCheckServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException { HttpSession session=req.getSession(); String randomCode=(String)session.getAttribute("randomCode"); if(null==randomCode) { resp.sendRedirect("login.html"); return; } String reqRandom=req.getParameter("random"); req.setCharacterEncoding("GBK"); resp.setContentType("text/html;charset=GBK"); PrintWriter out=resp.getWriter(); if(randomCode.equals(reqRandom)) { out.println("验证码匹配!"); } else { out.println("验证码校验失败,请返回重新输入!"); } out.close(); } }