五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

javabean+servlet應(yīng)用

2023-06-24 23:19 作者:G7oose  | 我要投稿

login.jsp


<%@ page language="java" isErrorPage="true" pageEncoding="utf-8"%>

<!DOCTYPE html>


<head>

<meta charset="utf-8">

<title></title>

<link rel="stylesheet" type="text/css" href="style.css" />

</head>

<body>

<div class="container">

? ? <section id="content">

? ? ? ? <form action="${pageContext.request.contextPath}/Servlet/Userservlet?method=login" method="post"><!---${pageContext.request.contextPath}的目的是找到主工程的名字,/Servlet/Userservlet就是web.xml下面配置的路徑,也就是servlet的路徑--->


? ? ? ? ? ? <h1>登錄 界面</h1>

? ? ? ? ? ? <div>

? ? ? ? ? ? ? ? <input type="text" placeholder="登錄名" required="" id="username" name="username1"/>

? ? ? ? ? ? </div>

? ? ? ? ? ? <div>

? ? ? ? ? ? ? ? <input type="password" placeholder="密碼" required="" id="password" name="password1" />

? ? ? ? ? ? </div>

? ? ? ? ? ? <div>

? ? ? ? ? ? ? ? <input type="submit" value="登 錄" />

? ? ? ? ? ? ? ? <a href="#">注冊(cè)</a>

? ? ? ? ? ? </div>

? ? ? ? </form><!-- form -->

? ? ? ? <div class="button">

? ? ? ? </div><!-- button -->

? ? </section><!-- content -->

</div><!-- container -->

</body>

</html>



userbean.java


package bean;


public class Userbean {

? ? private String username;//用戶名

? ? private String password;//密碼都是與數(shù)據(jù)庫(kù)匹配的,下面是set和get函數(shù)

? ? public String getUsername() {

? ? ? ? return username;

? ? }

? ? public void setUsername(String username) {

? ? ? ? this.username = username;

? ? }

? ? public String getPassword() {

? ? ? ? return password;

? ? }

? ? public void setPassword(String password) {

? ? ? ? this.password = password;

? ? }

? ??


}


userservlet.java



package servlet;


import java.io.IOException;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import dao.Userdao;




@SuppressWarnings("serial")

public class Userservlet extends HttpServlet

{

? ? //當(dāng)從jsp跳轉(zhuǎn)到servlet類時(shí),首先執(zhí)行service函數(shù)(這是定理)

? ? protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException

? ? {

? ? ? ? req.setCharacterEncoding("utf-8");//設(shè)置字符集,避免亂碼

? ? ? ? //獲取jsp界面需要進(jìn)行的操作,

? ? ? ? String method = req.getParameter("method");

? ? ? ? if(method.equals("login"))//轉(zhuǎn)到login函數(shù)

? ? ? ? {

? ? ? ? ? ? login(req,resp);

? ? ? ? }

? ? }

? ? protected void login(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException

? ? {

? ? ? ? req.setCharacterEncoding("utf-8");

? ? ? ? String username = req.getParameter("username1");//獲取jsp界面的username1和password1的值

? ? ? ? String password = req.getParameter("password1");

? ? ? ? Userdao userdao = new Userdao();//創(chuàng)建Userdao的實(shí)例

? ? ? ? int flag = userdao.login(username, password);//用來(lái)判斷是否登陸成功

? ? ? ? if(flag==1)

? ? ? ? {

? ? ? ? ? ? System.out.println("登錄成功!");

? ? ? ? ? ? resp.sendRedirect(req.getContextPath()+"/index.jsp");

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? System.out.println("登錄失?。?#34;);

? ? ? ? }

? ? }


}




userdao.java



package dao;


import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;


import db.DBUtil;


public class Userdao {

? ? public int login(String username,String password)

? ? {

? ? ? ? Connection conn = DBUtil.getConn();//這里就是從DBUtil類里面得到連接

? ? ? ? Statement state =null;

? ? ? ? ResultSet rs = null;

? ? ? ? int flag=0;

? ? ? ? try

? ? ? ? {

? ? ? ? ? ? String sql = "select * from user where name = '"+username+"'";//SQL語(yǔ)句,

? ? ? ? ? ? state = conn.createStatement();

? ? ? ? ? ??

? ? ? ? ? ? rs=state.executeQuery(sql);

? ? ? ? ? ? if(rs.next())

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(rs.getString("password").equals(password))

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? flag=1;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? catch(Exception e)

? ? ? ? {

? ? ? ? ? ? e.printStackTrace();

? ? ? ? }

? ? ? ??

? ? ? ? finally

? ? ? ? {

? ? ? ? ? ? DBUtil.close(rs, state, conn);

? ? ? ? }

? ? ? ? return flag;

? ? }

? ??


}


javabean+servlet應(yīng)用的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
马山县| 汝南县| 罗定市| 华容县| 陈巴尔虎旗| 宁陵县| 白银市| 石嘴山市| 兴国县| 房山区| 安达市| 铜山县| 乌鲁木齐县| 浦东新区| 拜城县| 香河县| 新干县| 宁化县| 巴东县| 苗栗市| 拜城县| 姚安县| 长寿区| 同江市| 泽州县| 二连浩特市| 沾化县| 信丰县| 辉南县| 永清县| 四子王旗| 皮山县| 山东省| 集贤县| 外汇| 琼结县| 固始县| 新乡县| 武陟县| 昌都县| 韶关市|