软件工程概论——课堂测试1

简介: 设计思想:1.用1个页面,实现课程录入,提交后直接返回课程界面。2.应用html表单属性进行数据的提交。3.用servlet进行写入数据库和验证输入。源代码: My JSP 'reg.

设计思想:1.用1个页面,实现课程录入,提交后直接返回课程界面。2.应用html表单属性进行数据的提交。3.用servlet进行写入数据库和验证输入。

源代码:

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'reg.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
.label{
width: 20%
}
.controler{
width: 80%
}
</style>
<script type="text/javascript" src="js/Calendar3.js"></script>
</head>

<body>
<h1>用户注册</h1>
<hr>
<form name="regForm" action="servlet/RegServlet" method="post" >
<p>
<label for="name">姓名</label>
<input type="text" name="name" id="name" />
</p>
<p>年龄
<input type="text" name="age" id="age" />
</p>
<p>反馈
<textarea name="fankui" id="fankui"></textarea>
</p>
<p>
<input type="submit" name="tijiao" id="tijiao" value="提交" />
</p>
</form>
</body>
</html>

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DB.DBUtil;
import Dao.Daoadd;

public class RegServlet extends HttpServlet {

/**
* Constructor of the object.
*/
public RegServlet() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request,response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

request.setCharacterEncoding("utf-8");

DBUtil db=new DBUtil();
Connection conn =db.getConn();
String name =request.getParameter("name");
String age =request.getParameter("age");
String fankui =request.getParameter("fankui");
Daoadd add=new Daoadd();
if(!age.equals("王建民")&&!age.equals("刘力嘉")&&!age.equals("刘丹")&&!age.equals("王辉")&&!age.equals("杨子光"))
{
PrintWriter out = response.getWriter();
out.println("");
request.getRequestDispatcher("../fluse.jsp").forward(request,response);
}
else
{
if(!fankui.equals("一教")&&!fankui.equals("二教")&&!fankui.equals("三教")&&!fankui.equals("基教"))
{
request.getRequestDispatcher("../fu.jsp").forward(request,response);
}
else
{
try {
add.add(conn, name, age, fankui);
//response.setHeader("refresh","1;url = index.jsp");
request.getRequestDispatcher("../reg.jsp").forward(request,response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}



}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}

目录
相关文章
|
4月前
|
数据采集 人工智能 监控
人工智能驱动的软件工程:测试左移的崛起价值
本文探讨了人工智能驱动下测试左移理念在软件工程中的重要性,分析测试工程师在需求评估、AI代码生成及遗留系统优化中的关键作用,揭示AI带来的挑战与机遇,并指出测试工程师需提升技能、关注合规与可维护性,以在AI时代保障软件质量。
332 89
|
12月前
|
机器学习/深度学习 人工智能 安全
探索AI在软件工程中的最新应用:自动化测试与代码审查
探索AI在软件工程中的最新应用:自动化测试与代码审查
|
小程序 测试技术 程序员
『软件工程12』软件工程实践方法——软件测试
该文章详细阐述了软件测试的重要性和基本原则,并按测试阶段顺序介绍了单元测试、集成测试、确认测试以及系统测试的具体内容和实施步骤。
『软件工程12』软件工程实践方法——软件测试
|
测试技术 持续交付 UED
软件测试的艺术与科学:平衡创新与质量的探索在软件开发的波澜壮阔中,软件测试如同灯塔,指引着产品质量的方向。本文旨在深入探讨软件测试的核心价值,通过分析其在现代软件工程中的应用,揭示其背后的艺术性与科学性,并探讨如何在追求技术创新的同时确保产品的高质量标准。
软件测试不仅仅是技术活动,它融合了创造力和方法论,是软件开发过程中不可或缺的一环。本文首先概述了软件测试的重要性及其在项目生命周期中的角色,随后详细讨论了测试用例设计的创新方法、自动化测试的策略与挑战,以及如何通过持续集成/持续部署(CI/CD)流程优化产品质量。最后,文章强调了团队间沟通在确保测试有效性中的关键作用,并通过案例分析展示了这些原则在实践中的应用。
306 1
|
敏捷开发 机器学习/深度学习 人工智能
探索式测试在现代软件工程中的实践与挑战
随着软件开发模式的迭代升级,传统的测试方法已不能完全满足快速变化的市场需求和敏捷开发的节奏。探索式测试作为一种灵活、启发式的测试实践,逐渐受到业界的关注。本文将深入探讨探索式测试的定义、特点及其在现代软件工程中的应用,并分析实施过程中可能遇到的挑战,旨在为软件测试人员提供一种创新的测试视角和方法。
|
SQL 存储 Java
程序技术好文:软件工程概论第一次课堂测试
程序技术好文:软件工程概论第一次课堂测试
93 0
|
10月前
|
数据可视化 前端开发 测试技术
接口测试新选择:Postman替代方案全解析
在软件开发中,接口测试工具至关重要。Postman长期占据主导地位,但随着国产工具的崛起,越来越多开发者转向更适合中国市场的替代方案——Apifox。它不仅支持中英文切换、完全免费不限人数,还具备强大的可视化操作、自动生成文档和API调试功能,极大简化了开发流程。
|
5月前
|
Java 测试技术 容器
Jmeter工具使用:HTTP接口性能测试实战
希望这篇文章能够帮助你初步理解如何使用JMeter进行HTTP接口性能测试,有兴趣的话,你可以研究更多关于JMeter的内容。记住,只有理解并掌握了这些工具,你才能充分利用它们发挥其应有的价值。+
974 23
|
7月前
|
SQL 安全 测试技术
2025接口测试全攻略:高并发、安全防护与六大工具实战指南
本文探讨高并发稳定性验证、安全防护实战及六大工具(Postman、RunnerGo、Apipost、JMeter、SoapUI、Fiddler)选型指南,助力构建未来接口测试体系。接口测试旨在验证数据传输、参数合法性、错误处理能力及性能安全性,其重要性体现在早期发现问题、保障系统稳定和支撑持续集成。常用方法包括功能、性能、安全性及兼容性测试,典型场景涵盖前后端分离开发、第三方服务集成与数据一致性检查。选择合适的工具需综合考虑需求与团队协作等因素。
1055 24
|
7月前
|
SQL 测试技术
除了postman还有什么接口测试工具
最好还是使用国内的接口测试软件,其实国内替换postman的软件有很多,这里我推荐使用yunedit-post这款接口测试工具来代替postman,因为它除了接口测试功能外,在动态参数的支持、后置处理执行sql语句等支持方面做得比较好。而且还有接口分享功能,可以生成接口文档给团队在线浏览。
326 2
下一篇
oss云网关配置