欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaWeb之Servlet注冊(cè)頁(yè)面的實(shí)現(xiàn)示例

 更新時(shí)間:2022年04月11日 11:31:55   作者:黑桃魚  
注冊(cè)頁(yè)面是很多網(wǎng)站都會(huì)是使用的到,本文主要介紹了JavaWeb之Servlet注冊(cè)頁(yè)面的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Servlet-注冊(cè)頁(yè)面

環(huán)境準(zhǔn)備:

本文所用到環(huán)境如下:

軟件:Eclipse(2018)

服務(wù)器:Tomcat 9

image-20220410201745892

image-20220410202055002

image-20220410202849114

image-20220410202352747

image-20220410203937149

image-20220410203345395

image-20220410203358312

image-20220410204121620

image-20220410204152464

image-20220410204213630

在index.jsp添加相關(guān)的代碼

<%@ page language="java" contentType="text/html; charset=UTF-8"
    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=UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>用戶注冊(cè)</h1>
<div>
    <form action="RegisterServlet" method="get">
    <table>
    <tr>
    <td>登錄名:</td> 
    <td><input type="text" name="username" required> (可包含a-z、0-9和下劃線)</td>
    </br>
    <tr>
    <td>密碼:</td> 
    <td><input type="password" name="password" required> (至少包含6個(gè)字符)</td>
    </tr>
    <tr>
    <td>再次輸入密碼:</td> 
    <td><input type="password" name="confirmPassword" required></td>
    </tr>
    <tr>
    <td>電子郵箱:</td> 
    <td><input type="text" id="email" name="youxaing" required> (必須包含@字符)</td>
    </tr>
    <tr>
    <td>性別:</td> 
    <td><input type="radio" name="gender" value="男" required>男
        <input type="radio" name="gender" value="女" required>女</td>
    </tr>
     <td>頭像:</td> 
    <td><input type="file" name="bfile" value="選擇文件" accept="image/*" ></td>
    </tr>
     <td>愛(ài)好:</td> 
    <td>
    <p>
   	  <input type="checkbox" name="hobby" value="運(yùn)動(dòng)"> 運(yùn)動(dòng)
      <input type="checkbox" name="hobby" value="聊天" > 聊天
      <input type="checkbox" name="hobby" value="玩游戲" > 玩游戲</p>
      
    </td>
    </tr>
   
     </tr>
     <td>喜歡的城市:</td> 
    <td>
         <select name="selectList">
         <option>[請(qǐng)選擇]</option>
         <option>北海</option>
         <option>海南</option>
         <option>重慶</option>
         <option>杭州</option>
         <option>深圳</option>
         <option>成都</option>
     	 </select>
    </tr>    
    </table>
    <div>
    <p>
       <input type="submit" value="提交">
       <input type="reset" value="重置">
     </p>
     </div>
    </form>
</div>

</body>
</html>

效果為:

image-20220410204600840

image-20220410204646887

image-20220410204927582

image-20220410205033911

image-20220410210010120

image-20220410205310735

Login_Servlet.java代碼

package onlyxiu_ceshi.com;

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;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class Login_Servlet
 */
@WebServlet("/Login_Servlet")
public class Login_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Login_Servlet() {
        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
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		
		
		 request.setCharacterEncoding("UTF-8");//處理亂碼問(wèn)題
	        response.setCharacterEncoding("UTF-8");//處理亂碼問(wèn)題
	        //獲得用戶在register界面提交的數(shù)據(jù)
	        String username = request.getParameter("username");
	        String password = request.getParameter("password");
	        String confirmPassword = request.getParameter("confirmPassword");
	        String gender = request.getParameter("gender");
	        String youxaing = request.getParameter("youxaing");
	        String bfile = request.getParameter("bfile");
	        String hobby  = request.getParameter("hobby");
	        String selectList = request.getParameter("selectList");
	        //判斷密碼是否正確
	        if (password.equals(confirmPassword)){//如果密碼相同,重定向到成功界面
	            HttpSession session = request.getSession();//獲取session
	            session.setAttribute("session_username",username);
	            session.setAttribute("session_password",password);
	            session.setAttribute("session_gender",gender);
	            session.setAttribute("session_youxaing",youxaing);
	            session.setAttribute("session_bfile",bfile);
	            session.setAttribute("session_hobby", hobby);
	            session.setAttribute("session_selectList",selectList);
	           
	            request.getRequestDispatcher("SuccessServlet").forward(request, response);
	          //  response.sendRedirect("register_login.jsp");//重定向到成功頁(yè)面
	        }else {//如果密碼不同,通知用戶密碼輸入不一樣
	            request.getSession().setAttribute("passwordError","yes");
	            request.getRequestDispatcher("ErrorServlet").forward(request, response);
//	            response.sendRedirect("register.jsp");//重定向到登陸界面
	        }
	    }
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>onlyxiu_ceshi</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>Login_Servlet</servlet-name>
    <servlet-class>onlyxiu_ceshi.com</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Login_Servlet</servlet-name>
    <url-pattern>/onlyxiu_ceshi/Login_Servlet</url-pattern>
  </servlet-mapping>
  
</web-app>

image-20220410205637467

ErrorServlet.java的代碼

package onlyxiu_ceshi.com;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ErrorServlet
 */
@WebServlet("/ErrorServlet")
public class ErrorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ErrorServlet() {
        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
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		
		response.setHeader("Content-type","text/html; charset=UTF-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String gender = request.getParameter("gender");
		String youxaing = request.getParameter("youxaing");
		String bfile = request.getParameter("bfile");
		String hobby = request.getParameter("hobby");
		String selectList = request.getParameter("selectList");
		PrintWriter out = response.getWriter();
		out.print("<h1>用戶注冊(cè)信息</h1>");
		out.print("用戶名:\n"+username+"<br>");
		out.print("密碼:"+password+"<br>");
		out.print("電子郵箱:"+youxaing+"<br>");
		out.print("性別:"+gender+"<br>");
		out.print("頭像:"+bfile+"<br>");
		out.print("愛(ài)好:"+hobby+"<br>");
		out.print("喜歡的城市:"+selectList+"<br>");
//		out.print("登陸失敗");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		doGet(request, response);
	}

}

SuccessServlet.java

package onlyxiu_ceshi.com;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class SuccessServlet
 */
@WebServlet("/SuccessServlet")
public class SuccessServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SuccessServlet() {
        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
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		response.setHeader("Content-type","text/html; charset=UTF-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String gender = request.getParameter("gender");
		String youxaing = request.getParameter("youxaing");
		String bfile = request.getParameter("bfile");
		String hobby = request.getParameter("hobby");
		String selectList = request.getParameter("selectList");
		PrintWriter out = response.getWriter();
		out.print("<h1>用戶注冊(cè)信息</h1>");
		out.print("用戶名:\n"+username+"<br>");
		out.print("密碼:"+password+"<br>");
		out.print("電子郵箱:"+youxaing+"<br>");
		out.print("性別:"+gender+"<br>");
		out.print("頭像:"+bfile+"<br>");
		out.print("愛(ài)好:"+hobby+"<br>");
		out.print("喜歡的城市:"+selectList+"<br>");
//		out.println("登陸成功");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		doGet(request, response);
	}

}

image-20220410210256565

image-20220410210243740

 到此這篇關(guān)于JavaWeb之Servlet注冊(cè)頁(yè)面的實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)Servlet注冊(cè)頁(yè)面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)文件編碼轉(zhuǎn)換的方法

    java實(shí)現(xiàn)文件編碼轉(zhuǎn)換的方法

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)文件編碼轉(zhuǎn)換的方法,分享一個(gè)文件編碼轉(zhuǎn)換的工具類,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • mybatis-plus使用generator實(shí)現(xiàn)逆向工程

    mybatis-plus使用generator實(shí)現(xiàn)逆向工程

    mybatis-plus-generator在3.5.0以及以后的版本使用新的方式逆向生成代碼,本文主要介紹了mybatis-plus使用generator實(shí)現(xiàn)逆向工程,具有一定的參考價(jià)值,感興趣的可以了解一下
    2022-05-05
  • hibernate中HQL如何調(diào)用自定義函數(shù)

    hibernate中HQL如何調(diào)用自定義函數(shù)

    這篇文章主要介紹了hibernate中HQL如何調(diào)用自定義函數(shù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Spring接口ApplicationRunner用法詳解

    Spring接口ApplicationRunner用法詳解

    這篇文章主要介紹了Spring接口ApplicationRunner的作用和使用介紹,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-08-08
  • Java 實(shí)現(xiàn)FTP服務(wù)實(shí)例詳解

    Java 實(shí)現(xiàn)FTP服務(wù)實(shí)例詳解

    這篇文章主要介紹了Java 實(shí)現(xiàn)FTP服務(wù)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • Spring boot AOP通過(guò)XML配置文件聲明的方法

    Spring boot AOP通過(guò)XML配置文件聲明的方法

    這篇文章主要介紹了Spring boot AOP通過(guò)XML配置文件聲明,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • java中的移位運(yùn)算符心得總結(jié)

    java中的移位運(yùn)算符心得總結(jié)

    這篇文章介紹了java中的移位運(yùn)算符,有需要的朋友可以參考一下
    2013-11-11
  • Java中的字符串用法小結(jié)

    Java中的字符串用法小結(jié)

    這篇文章主要介紹了Java中的字符串用法,實(shí)例總結(jié)了java中關(guān)于字符串操作的各種常用的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • SpringBoot?@GroupSequenceProvider注解實(shí)現(xiàn)bean多屬性聯(lián)合校驗(yàn)的示例代碼

    SpringBoot?@GroupSequenceProvider注解實(shí)現(xiàn)bean多屬性聯(lián)合校驗(yàn)的示例代碼

    這篇文章主要介紹了SpringBoot?@GroupSequenceProvider注解實(shí)現(xiàn)bean多屬性聯(lián)合校驗(yàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • Java實(shí)現(xiàn)控制臺(tái)輸出兩點(diǎn)間距離

    Java實(shí)現(xiàn)控制臺(tái)輸出兩點(diǎn)間距離

    這篇文章主要介紹了Java實(shí)現(xiàn)控制臺(tái)輸出兩點(diǎn)間距離,涉及了部分編程坐標(biāo)的問(wèn)題,具有一定參考價(jià)值,需要的朋友可以了解下
    2017-09-09

最新評(píng)論