java web的课堂练习-找零钱-学生管理系统
2022/4/9 1:49:07
本文主要是介绍java web的课堂练习-找零钱-学生管理系统,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、找零钱
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function change()
{
money=Number(document.form1.txt1.value);
if(money!=parseInt(money)||money<1||money>100)
{
alert("请输入一个1-100的整数")
}
else{
var a=Math.floor(money/50);
var b=Math.floor((money-50*a)/20);
var c=Math.floor((money-50*a-20*b)/10);
var d=Math.floor((money-50*a-20*b-10*c)/5);
var e=(money-50*a-20*b-10*c-5*d);
alert("找零:"+"50元"+a+"张;20元"+b+"张;10元"+c+"张;5元"+d+"张;1元"+e+"张。") //alert是输出
}
}
</script>
输入要找的零钱
<form name="form1">
<input name="txt1" type="text"><br>
<input type="button" onclick="change()" value="找零"><br>
</form>
</body>
</html>
二、学生管理系统
<%@ page language="java" import="java.util.*" pageEncoding="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>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dsschool","root","123");
Statement stat = conn.createStatement();
String sql ="SELECT * FROM T_STUDENT";
ResultSet rs = stat.executeQuery(sql);
while(rs.next()){
String stuno = rs.getString("STUNO");
String stuname = rs.getString("STUNAME");
String stusex = rs.getString("STUSEX");
out.println(stuno + " " + stuname + " "+stusex+"<br>");
}
stat.close();
conn.close();
%>
</body>
</html>
//同题不同页
<%@ page language="java" import="java.util.*" pageEncoding="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>
<body>
<script type="text/javascript">
function validate(){
if(select.stuname1.value==""){
alert("查询内容不能为空!");
return;
}
select.submit();
}
</script>
查询学生信息<br>
<form name="select" action = "ans02_2.jsp"method="post">
请输入学生姓名:<input type="text" name="stuname1"><br>
<input type="button" value="查询" onCick="validate()">
</form>
</body>
</html>
<%@ page language="java" import="java.sql.*" pageEncoding="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>
<body>
<%request.setCharacterEncoding("utf-8"); %>
<%
String stuname1=request.getParameter("stuname1");
if(stuname1 != null){
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dsschool","root","123");
String sql="SELECT * FROM T_STUDENT where stuname like '%"+stuname1+"%'";
PreparedStatement stat=conn.prepareStatement(sql);
ResultSet rs=stat.executeQuery();
//out.print(sql);
while(rs.next()){
String stuno=rs.getString(1);
String stuname=rs.getString(2);
String stusex=rs.getString(3);
out.println(stuno+" " +stuname+" "+stusex+"<BR>");
}
stat.close();
conn.close();
}
%>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="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>
<body>
学生登陆<br>
<form method="post">
请输入学生学号:<input type ="text" name="stuno"><br>
请输入学生姓名:<input type ="text" name="stuname"><br>
<input type ="submit" value="登录">
</form>
<%request.setCharacterEncoding("utf-8"); %>
<%
String stuno=request.getParameter("stuno");
String stuname=request.getParameter("stuname");
if(stuno!=null&&stuname!=null){
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dsschool","root","123");
PreparedStatement stat=null;
ResultSet rs=null;
String sql="SELECT *FROM t_STUDENT WHERE STUNO=?&&STUNAME=?";
stat=conn.prepareStatement(sql);
stat.setString(1,stuno);
stat.setString(2,stuname);
rs=stat.executeQuery();
if(rs.next()){
out.println("登陆成功");
}
else{
out.println("登陆失败");
}
stat.close();
conn.close();
}
%>
</body>
</html>
这篇关于java web的课堂练习-找零钱-学生管理系统的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南