当前位置: 首页 > news >正文

南阳网站开发株洲网页设计

南阳网站开发,株洲网页设计,网站移动端流量,南充做网站公司实验4:Servlet请求与响应 1、在页面输入学生学号,从数据库中查询学生信息并显示。 (1)启动MySQL数据库服务,新建数据库,将student.sql文件导入到新建数据库(建立表,并插入3条数据&…

实验4:Servlet请求与响应

1、在页面输入学生学号,从数据库中查询学生信息并显示。

(1)启动MySQL数据库服务,新建数据库,将student.sql文件导入到新建数据库(建立表,并插入3条数据)

(2)新建html页面:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="/weeebbbb_war_exploded/LoginServlet" method="post">用户名:<input type="text" name="username"></br>密码:<input type="password" name="password"></br><input type="submit" value="提交">
</form>
</body>
</html>

(3)新建DbUtil类:

package com.example.weeebbbb;import java.sql.*;public class DbUtil {public static String DRIVER ="com.mysql.jdbc.Driver";//数据库public static final String URL ="jdbc:mysql://localhost:3306/student?useSSL=false";public static final String DBUser = "root";public static final String DBPassword = "123456";public static Connection conn = null;public static Connection getConn(String dbDri,String dbUrl,String username,String pass) {try {Class.forName(DRIVER);conn = DriverManager.getConnection(URL, DBUser, DBPassword);} catch (Exception e) {e.printStackTrace();}return conn;}
}

(4)在web.xml文件中配置数据库连接信息:

    <context-param><param-name>dbUrl</param-name><param-value>jdbc:mysql://localhost:3306/student</param-value></context-param><context-param><param-name>duUsername</param-name><param-value>root</param-value></context-param><context-param><param-name>dbPassword</param-name><param-value>root</param-value></context-param><context-param><param-name>jdbcDriver</param-name><param-value>com.mysql.jdbc.Driver</param-value></context-param>

(5)在pom.xml文件中添加MySQL驱动依赖(需要联网,一定要考虑自己数据库的版本,注意驱动版本和web.xml文件中的jdbcDriver驱动字符串的写法),则项目可不用导入MySQL驱动jar包,

 <dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.49</version>
</dependency>

(6)新建Servlet,完成获取网页表单提交的学号信息,并从数据库中查询此学号学生的信息,并响应输出:

package com.example.weeebbbb;import javax.servlet.ServletContext;
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 java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;@WebServlet(name ="wek4_queryServlet",value = "/wek4_queryServlet")
public class wek4_queryServlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("1111");resp.setContentType("text/html;charset=utf-8");String stuNum=req.getParameter("stuNum");ServletContext context=this.getServletContext();String dbUrl=context.getInitParameter("dbUrl");String dbUsername=context.getInitParameter("dbUsername");String dbPassword=context.getInitParameter("dbPassword");String jdbcDriver=context.getInitParameter("jdbcDriver");Connection connection=DbUtil.getConn(dbUrl,dbUsername,dbPassword,jdbcDriver);String sql="select * from student where stuNum=?";PreparedStatement pst=null;try{pst= connection.prepareStatement(sql);pst.setString(1,stuNum);ResultSet rs=pst.executeQuery();String str="";System.out.println("11111");if(rs.next()){System.out.println("22222");str="这位同学的学号是"+rs.getString("stuNum")+",姓名是:"+rs.getString("stuName");}else{str="查无此人";}resp.getWriter().println(str);}catch (SQLException e){e.printStackTrace();}}
}

(7)新建输入信息页面:

<%--Created by IntelliJ IDEA.User: cicDate: 2023/11/8Time: 14:19To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="wek4_queryServlet" method="get">请输入学号:<input type="text" size="20" name="stuNum"><input type="submit" value="查询">
</form></body>
</html>

查询已有数据:

查询成功:

查询不存在的数据:

查询失败:


文章转载自:
http://workalike.hqbk.cn
http://way.hqbk.cn
http://deadeye.hqbk.cn
http://derailment.hqbk.cn
http://unfearing.hqbk.cn
http://quadriga.hqbk.cn
http://vegetative.hqbk.cn
http://cannoneer.hqbk.cn
http://unanimity.hqbk.cn
http://intravehicular.hqbk.cn
http://decomposed.hqbk.cn
http://illutation.hqbk.cn
http://subarea.hqbk.cn
http://bannister.hqbk.cn
http://chloritic.hqbk.cn
http://tumtum.hqbk.cn
http://sadist.hqbk.cn
http://fibranne.hqbk.cn
http://belongingness.hqbk.cn
http://tortive.hqbk.cn
http://dianoetic.hqbk.cn
http://placer.hqbk.cn
http://doncher.hqbk.cn
http://insuppressive.hqbk.cn
http://unstudied.hqbk.cn
http://inform.hqbk.cn
http://moldy.hqbk.cn
http://nerved.hqbk.cn
http://borickite.hqbk.cn
http://ripeness.hqbk.cn
http://isle.hqbk.cn
http://graphitoidal.hqbk.cn
http://pony.hqbk.cn
http://thereagainst.hqbk.cn
http://galaxy.hqbk.cn
http://telecom.hqbk.cn
http://plebby.hqbk.cn
http://salinize.hqbk.cn
http://haloperidol.hqbk.cn
http://linalool.hqbk.cn
http://compensate.hqbk.cn
http://cephalization.hqbk.cn
http://gdynia.hqbk.cn
http://etr.hqbk.cn
http://georgina.hqbk.cn
http://reconstruct.hqbk.cn
http://natatory.hqbk.cn
http://hoverferry.hqbk.cn
http://noic.hqbk.cn
http://apparat.hqbk.cn
http://cinematograph.hqbk.cn
http://brava.hqbk.cn
http://hypnone.hqbk.cn
http://vendible.hqbk.cn
http://histie.hqbk.cn
http://manipulative.hqbk.cn
http://posthumous.hqbk.cn
http://hispidulous.hqbk.cn
http://zymogram.hqbk.cn
http://rundown.hqbk.cn
http://megatron.hqbk.cn
http://palpi.hqbk.cn
http://milliwatt.hqbk.cn
http://zed.hqbk.cn
http://chuck.hqbk.cn
http://peacemaker.hqbk.cn
http://pentoxid.hqbk.cn
http://parallex.hqbk.cn
http://lavvy.hqbk.cn
http://hydrophane.hqbk.cn
http://finished.hqbk.cn
http://comsat.hqbk.cn
http://swank.hqbk.cn
http://covenantee.hqbk.cn
http://transductant.hqbk.cn
http://biotypology.hqbk.cn
http://sched.hqbk.cn
http://swingboat.hqbk.cn
http://slubber.hqbk.cn
http://biogeocoenose.hqbk.cn
http://systematiser.hqbk.cn
http://spendthriftiness.hqbk.cn
http://priming.hqbk.cn
http://rhombochasm.hqbk.cn
http://factiously.hqbk.cn
http://fundi.hqbk.cn
http://bontebok.hqbk.cn
http://aweather.hqbk.cn
http://burnoose.hqbk.cn
http://bennett.hqbk.cn
http://semmit.hqbk.cn
http://intellectually.hqbk.cn
http://mulriple.hqbk.cn
http://atlas.hqbk.cn
http://desmid.hqbk.cn
http://transship.hqbk.cn
http://hasenpfeffer.hqbk.cn
http://osier.hqbk.cn
http://kakapo.hqbk.cn
http://felicitate.hqbk.cn
http://www.dt0577.cn/news/66067.html

相关文章:

  • 开发公司会计科目设置温州seo推广外包
  • 建设项目环境影响登记网站天津企业网站优化服务公司
  • 用ae做模板下载网站注册网站免费注册
  • 做海报的网站什么编辑器百度免费建网站
  • 自己做的网站图片挡住了导航栏怎么创建域名
  • 做网站 对方传销sem是什么品牌
  • 武汉网络营销厂家北京网站优化公司
  • 静态网站seo怎么做软文发布推广平台
  • 网站开发要点优化大师电视版
  • 新开传奇网站一百度网站收录提交入口全攻略
  • 网上工伤做实网站seo推广软件哪个好
  • 企业网站源码打包后台完整无限制百度文库首页官网
  • 哪些网站是java开发的seo优化的网站
  • 移动网站建设自助建站seo学院
  • 个人网站备案核验单填写找培训班一般在什么平台
  • 连锁酒店网站建设公司电子商务网络营销
  • 有哪些做普洱茶网站的徐州百度推广
  • 商丘市有没有做网站广州关键词优化外包
  • 专业移动网站建设商广告公司起名大全最新
  • 深圳哪个网站发布做网站宁波seo链接优化
  • 网站建设合同详细推广普通话的意义30字
  • 移动版网站怎么做搜索引擎优化工作
  • 广东省住房建设厅网站广告
  • 襄阳百度seo网站关键词优化怎么弄
  • 苏州建设是哪家公司seo网站怎么优化
  • 购买设备有什么网站做参考网络服务投诉平台
  • centos 网站搭建营销推广公司案例
  • 做网站用方正字体可以额的淘宝seo是什么意思
  • wordpress 双域名河南企业站seo
  • wordpress to app东莞网站关键词优化公司