---
title: "JSP-ServLet 一个简单的密码核对"
author: "danielhjd"
date: "2011-03-28T16:35:30Z"
tags: ["JSP", "Servlet"]
categories: ["编程语言"]
slug: "jsp-servlet"
draft: false
lastmod: "2011-03-28T16:35:30Z"
id: 977563
url: "https://danielhjd.iteye.com/blog/977563"
---

First Step: Create One Jsp file: \[color=blue]Login\[/color].jsp This is my JSP page.

Login Password

Second Step: Create One ServLet File: \[color=red]LoginServLet\[/color].java public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name =request.getParameter("username"); String password=request.getParameter("pwd"); HttpSession session=request.getSession(); if (name.equals("dgy")&&password.equals("123")){ System.out.println("login Successfully"); session.setAttribute("username",name); session.setAttribute("password",password); request.getRequestDispatcher("LoginSuccess.jsp").forward(request, response); }else{ System.out.println("Oops!!! pls correct"); response.sendRedirect("\[color=blue]Login\[/color].jsp"); } } Third Step: Creat another jsp: LoginSuccess.jsp This is my JSP page.  
Username:${username} Password:${password}