java小练习

java小练习_第1张图片

首页代码:





Insert title here


	
请输入账号:
请输入密码:

servlst代码:



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


@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String lname = request.getParameter("lname");
		String lpass = request.getParameter("lpass");
		//把账号密码存到request中
		request.setAttribute("lname", lname);
		request.setAttribute("lpas", lpass);
		if((lname.equals("admin")&&lpass.equals("123"))||(lname.equals("haha")&&lpass.equals("123")))
		{
			request.getRequestDispatcher("/manage.jsp").forward(request, response);
		}
		else{
			request.getRequestDispatcher("/index.html").forward(request, response);
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}

登陆成功页面:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	String lname = (String)request.getAttribute("lname");
	String lpass = (String)request.getAttribute("lpass");
%>




Insert title here


	欢迎您,<%=lname %>
	


你可能感兴趣的:(java小练习)