您的位置:首页 > 房产 > 建筑 > 网络营销是什么时候兴起的_营销技巧分享_信息流广告怎么投放_网站seo提升

网络营销是什么时候兴起的_营销技巧分享_信息流广告怎么投放_网站seo提升

2025/2/23 6:00:30 来源:https://blog.csdn.net/2301_80189168/article/details/144071407  浏览:    关键词:网络营销是什么时候兴起的_营销技巧分享_信息流广告怎么投放_网站seo提升
网络营销是什么时候兴起的_营销技巧分享_信息流广告怎么投放_网站seo提升

文章目录

  • 目录结构
  • 处理类爆炸问题
  • 功能测试

目录结构

将同一个业务的后端程序整合到一个类中,也是MVC 分层,的雏形
分类 整合
在这里插入图片描述

处理类爆炸问题

package com.yanyu;import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import resources.DBUtil;import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;/*** @Author yanyu666_508200729@qq.com* @Date 2024/11/26 21:53* @description:解决类爆炸问题* 1.模拟  HttpServlet 的模板设计思想* 2.注解式开发* 3. 在原项目   stuid   基础 上开发,并修改号对应的  项目名字*/
@WebServlet({"/list","/modifyStuno","/modify","/delete","/add"})
public class StudentService extends HttpServlet {@Overrideprotected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//获取  servlet  对象的路径   /web2/list    web2  项目名字,   /listString servletPath = request.getServletPath();//    /listif ("/list".equals(servletPath)) {
//           利用已知道的常量来调研方法,避开空引用异常
//            将  浏览器的请求对象带入doList(request, response);} else if ("/add".equals(servletPath)) {doAdd(request,response);//   alt   enter}else if ("/delete".equals(servletPath)){doDel(request,response);//   不要设置为  doDelete()   会与  HttpServlet 的   doDelete()} else if ("/modifyStuno".equals(servletPath)) {doModifyStuno(request,response);} else if ("/modify".equals(servletPath)) {doModify(request,response);}}private void doModify(HttpServletRequest request, HttpServletResponse response) throws IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");response.setContentType("text/html");PrintWriter out = response.getWriter();String name = request.getParameter("name");String stuid = request.getParameter("stuid");String zhuanye = request.getParameter("zhuanye");Connection connection = null;Statement statement = null;ResultSet rs = null;try {connection =  DBUtil.getConnection();connection.setAutoCommit(false);String sql = "update student set name = '"+name+"',zhuanye = '"+zhuanye+"' where stuid = '"+stuid+"'";statement = connection.createStatement();statement.executeUpdate(sql);connection.commit();} catch (SQLException e) {if (connection != null) {try {connection.close();} catch (SQLException ex) {throw new RuntimeException(ex);}}throw new RuntimeException(e);}finally {DBUtil.close(rs,statement,connection);}response.sendRedirect("/web2/list");}private void doModifyStuno(HttpServletRequest request, HttpServletResponse response) throws IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");response.setContentType("text/html");PrintWriter out = response.getWriter();
//        获取待续该学生的学号String stuno = request.getParameter("stuno");Connection connection = null;Statement statement = null;ResultSet rs = null;try {connection = DBUtil.getConnection();connection.setAutoCommit(false);
//            获取 该学生的信息String sql = "select * from student where stuid = '" + stuno + "'";statement = connection.createStatement();rs = statement.executeQuery(sql);while (rs.next()) {String name = rs.getString("name");
//                rs.getString("stuid");String zhuanye = rs.getString("zhuanye");out.print("<!DOCTYPE html>");out.print("<html lang='en'>");out.print("<head>");out.print("    <meta charset='UTF-8'>");out.print("    <meta name='viewport' content='width=device-width, initial-scale=1.0'>");out.print("    <title>Document</title>");out.print("</head>");out.print("<body>");out.print("    <h1>修改学生</h1>");
//                设置  修改后的学生信息out.print("    <form action='/web2/modify'>");out.print("                    原姓名:"+name+"");out.print("                    <br>");out.print("            原学号:"+stuno+"");out.print("                    <br>");out.print("                    原专业:"+zhuanye+"");out.print("                    <br>");out.print("            姓名:<input type='text' name='name'>");out.print("        <br>");
//                修改前后,学号是不变的,所以要把学号拼接到   学号输入框   ,并将输入框设置为  只读不可修改out.print("                    学号:<input type='text' name='stuid' value='"+stuno+"' readonly>");out.print("        <br>");out.print("                    专业:<input type='text' name='zhuanye' >");out.print("        <br><input type='submit' value='确认修改'>");out.print("    </form>");out.print("</body>");out.print("</html>");}connection.commit();} catch (SQLException e) {if (connection != null) {try {connection.rollback();} catch (SQLException ex) {throw new RuntimeException(ex);}}throw new RuntimeException(e);}finally {DBUtil.close(rs,statement,connection);}}private void doDel(HttpServletRequest request, HttpServletResponse response) throws IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");response.setContentType("text/html");PrintWriter out = response.getWriter();
//        获取待续该学生的学号String delno = request.getParameter("delno");Connection connection = null;Statement statement = null;ResultSet rs = null;try {connection = DBUtil.getConnection();connection.setAutoCommit(false);String sql = "delete from student where stuid = '"+delno+"'";statement = connection.createStatement();statement.execute(sql);connection.commit();} catch (SQLException e) {if (connection != null) {try {connection.rollback();} catch (SQLException ex) {throw new RuntimeException(ex);}}throw new RuntimeException(e);}finally {DBUtil.close(rs,statement,connection);}response.sendRedirect("/web2/list");}private void doAdd(HttpServletRequest request, HttpServletResponse response) throws IOException {request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");response.setContentType("text/html");PrintWriter out = response.getWriter();String name = request.getParameter("name");String stuid = request.getParameter("stuid");String zhuanye = request.getParameter("zhuanye");Connection connection = null;Statement statement = null;ResultSet rs = null;try {connection =  DBUtil.getConnection();connection.setAutoCommit(false);String sql = "insert into student(name,stuid,zhuanye) values('"+name+"','"+stuid+"','"+zhuanye+"') ";statement = connection.createStatement();statement.execute(sql);connection.commit();} catch (SQLException e) {if (connection != null) {try {connection.rollback();} catch (SQLException ex) {throw new RuntimeException(ex);}}throw new RuntimeException(e);}finally {DBUtil.close(rs,statement,connection);}response.sendRedirect("/web2/list");}private void doList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//        处理整个查询业务   IO异常交给tomcat 处理request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8");response.setContentType("text/html");PrintWriter out = response.getWriter();Connection connection = null;Statement statement = null;ResultSet rs = null;try {connection = DBUtil.getConnection();connection.setAutoCommit(false);String sql = "select * from student";statement = connection.createStatement();rs = statement.executeQuery(sql);out.print("<!DOCTYPE html>");out.print("<html lang='en'>");out.print("<head>");out.print("    <meta charset='UTF-8'>");out.print("    <meta name='viewport' content='width=device-width, initial-scale=1.0'>");out.print("    <title>Document</title>");out.print("</head>");out.print("<body>");out.print("    <h1>学生信息</h1>");out.print("    <table border='1px' width='600px'>");out.print("        <tr>");out.print("            <td>姓名</td>");out.print("            <td>学号</td>");out.print("            <td>专业</td>");out.print("            <td>操作</td>");out.print("        </tr>");while (rs.next()) {String name = rs.getString("name");String stuid = rs.getString("stuid");String zhuanye = rs.getString("zhuanye");out.print("        <tr></tr>");out.print("            <td>" + name + "</td>");out.print("            <td>" + stuid + "</td>");out.print("            <td>" + zhuanye + "</td>");out.print("            <td>");out.print("                <a href='./add.html'>新增</a>");
//               发送修改学生信息之前   ,查询学生原来的信息        根据  stuid  在修改前后不变的原则out.print("                <a href='/web2/modifyStuno?stuno=" + stuid + "'>修改</a>");
//               根据  stuid   去限制  where  进行学生的  删除操作out.print("                <a href='/web2/delete?delno=" + stuid + "'>删除</a>");out.print("            </td>");out.print("        </tr>");}out.print("    </table>");out.print("</body>");out.print("</html>");connection.commit();} catch (SQLException e) {if (connection != null) {try {connection.rollback();} catch (SQLException ex) {throw new RuntimeException(ex);}}throw new RuntimeException(e);} finally {DBUtil.close(rs, statement, connection);}}
}

功能测试

在这里插入图片描述
其它功能正常

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com