国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ó)家法律
松江区| 青州市| 清流县| 广宗县| 文安县| 崇阳县| 寿光市| 洪泽县| 淮安市| 会理县| 顺昌县| 西华县| 新安县| 玛纳斯县| 洪泽县| 嵊泗县| 鲁山县| 新乡县| 临城县| 克什克腾旗| 康马县| 广宁县| 垣曲县| 仁布县| 开化县| 扎赉特旗| 门源| 会泽县| 庆元县| 凤凰县| 凤翔县| 澄迈县| 平武县| 铜山县| 射洪县| 栖霞市| 勃利县| 大名县| 巴东县| 兴化市| 章丘市|