今天进行了模拟售卖机的javaweb的简单编写,编写了大概的流程。代码量大概50行。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="toolse.Tll"%> <%@page import="java.util.*"%> <%@ page import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <style> p{ font-size: 25px} </style> <title>模拟自动售卖机</title> </head> <body> <% Connection conn = Tll.getConnection(); PreparedStatement pre = null; ResultSet res = null; String s1="",s2=""; String sql = "SELECT *FROM thing where name=? "; try { pre = conn.prepareStatement(sql); pre.setString(1,"可乐"); res = pre.executeQuery(); while (res.next()) { String num1 = res.getString("total"); String num2 =res.getString("num"); s1=num1; s2=num2; } } catch (SQLException e) { e.printStackTrace(); } finally { Tll.release(conn, pre, res); } %> <img alt="" src="images/1000.jpg" width='200' height='200'/> </br> <p><% out.print(s1); %></p> <p>剩余量<% out.print(s2); %> </p> <form action="Sere" method="post"> <input type="hidden" name="method" value="findAll"/> <input type="hidden" name="num" value="<%=s2 %>"/> <input type="submit" value="购买"> </form> </body> </html>
稍微实现数据的更新,但是需要界面的优化。
标签:总结,4.4,每日,售卖机,编写,模拟 From: https://www.cnblogs.com/syhxx/p/17288095.html