Login学习1

来源:互联网 发布:最火的网络流行歌曲 编辑:程序博客网 时间:2024/05/21 11:35




znLogin.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"    pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><form method = "post" action ="a">用户名  <input name="name" type = "text"><br>密码<input name = "psw" type="text"><br><input type="submit" value="login"></form></body></html>



ZnServlet.java

package zn;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;/** * Servlet implementation class ZnServlet */@WebServlet("/ZnServlet")public class ZnServlet extends HttpServlet {private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public ZnServlet() {        super();        // TODO Auto-generated constructor stub    }/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub}/** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubString sname = request.getParameter("name");String psd = request.getParameter("psw") ;System.out.println(sname);System.out.println(psd);}}



web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  <display-name>D</display-name>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list>       <servlet>    <servlet-name>aLogin</servlet-name>    <servlet-class>zn.ZnServlet</servlet-class>  </servlet>     <servlet-mapping>    <servlet-name>aLogin</servlet-name>    <url-pattern>/a</url-pattern>  </servlet-mapping>     </web-app>



0 0
原创粉丝点击