美好的一天。我是JSP的初学者,我将每日销售监控作为一个项目。我已经完成了我的研究,并且我已经制作了我的第一个CRUD jsp程序函数,但是当我添加了很多列时,插入不起作用(删除和查看仍然有效)。没有可见错误,但只要在读取页面上重定向,就不会加载最新数据。
我尝试在所有角度寻找错误,但我似乎无法找到它。我尝试计算所有列,重命名一些实例,但它仍然无法运行。你能解决我的问题吗?这是我第一次问这里,我似乎无法找到前面问题的答案。所有回复都将受到赞赏。
顺便说一句,我使用的是Netbeans IDE 8.1和Microsoft SQL Server
AddNew.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Add New</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Add New</h1>
<div style="width: 900px; margin-left: auto; margin-right: auto">
<form action="JSP/ManagerAddNew.jsp" method="post">
Station:
<input type="text" name="station" style="width: 200px" value="South Area Auto Gas Corp. - Kawit" readonly><br><br>
<!--Title:<br>
<input type="text" name="title" style="width: 200px" ><br>
-->
Date:
<input type="date" name="date" style="width: 200px"><br><br>
<!--Description:<br>
<input type="text" name="description" style="width: 200px"><br>
-->
Shift:
<select name="shift">
<option value="World">GY</option>
<option value="World">AM</option>
<option value="Tech">PM</option>
</select><br><br>
Product:
<select name="product">
<option value="World">LPG</option>
<option value="Tech">Diesel</option>
<option value="World">Unleaded</option>
<option value="Tech">Premium</option>
</select><br><br>
U/Price:
<input type="text" name="uprice" style="width: 200px">
No. of Transaction:
<input type="text" name="nooftrans" style="width: 50px"><br><br>
Cashier:
<input type="text" name="cashier" style="width: 300px"><br><br>
Tank 1:
<input type="text" name="tank1level" placeholder="gauge" style="width: 50px">
<input type="text" name="tank1liters" placeholder="liters" style="width: 50px"><br><br>
Tank 2:
<input type="text" name="tank2level" placeholder="gauge" style="width: 50px">
<input type="text" name="tank2liters" placeholder="liters" style="width: 50px"><br><br><br><br>
<table>
<tr>
<td>Description</td>
<td>Liters</td>
<td>Amount</td>
</tr>
<tr>
<td>Cash:</td>
<td><input type="text" name="cashliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="cashamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Card:</td>
<td><input type="text" name="cardliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="cardamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Charge:</td>
<td><input type="text" name="chargeliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="chargeamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>G.C:</td>
<td><input type="text" name="gcliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="gcamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Fleet Card:</td>
<td><input type="text" name="fleetliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="fleetamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Tapping:</td>
<td><input type="text" name="tappingliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="tappingamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Hosefill:</td>
<td><input type="text" name="hosefillliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="hosefillamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Calibration: </td>
<td><input type="text" name="calibrateliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="calibrateamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
<tr>
<td>Gross: </td>
<td><input type="text" name="grossliters" placeholder="liters" style="width: 50px"><br></td>
<td><input type="text" name="grossamt" placeholder="amount" style="width: 100px"><br></td>
</tr>
</table>
<br><br>
Deposit Amount:<br>
<input type="text" name="cashdepoamt" placeholder="gauge" style="width: 100px">
<input type="text" name="checkdepoamt" placeholder="liters" style="width: 100px">
<input type="text" name="variance" placeholder="liters" style="width: 100px"><br><br>
<!--
START NOTE: ADD TO EDIT LATER
-->
User ID:
<input type="text" name="userid" style="width: 300px"><br><br>
Transmit
<input type="text" name="transmit" style="width: 300px"><br><br>
Transmit Date:
<input type="date" name="transmitdate" style="width: 300px"><br><br>
Create Date:
<input type="date" name="createdate" style="width: 300px"><br><br>
<!--
NOTE: ADD TO EDIT LATER
-->
<!--Detail:<br>
<textarea name="detail" style="width: 400px; height: 200px"></textarea><br>
-->
<!--
Category:
<select name="category">
<option value="World">World</option>
<option value="Tech">Tech</option>
<option value="Sport">Sport</option>
</select><br>
-->
<!--Image:<br>
<input type="text" name="image" style="width: 200px"><br>
-->
<br><br><input type="submit" value="Submit">
</form>
<!--Complete Interface Addnew.-->
</div>
</body>
</html>
ManagerAddNew.jsp
<%--
Document : ManagerAddNew
Created on : Aug 8, 2015, 10:38:33 PM
Author : Thang
--%>
<%@page import="dao.DataAccess"%>
<%@page import="model.News"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.sql.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String station = request.getParameter("station"); //
String date = request.getParameter("date"); //
String shift = request.getParameter("shift"); //
String uprice = request.getParameter("uprice"); //
String cashliters = request.getParameter("cashliters");//
String cashamt = request.getParameter("cashamt");//
String cardliters = request.getParameter("cardliters");//
String cardamt = request.getParameter("cardamt");//
String chargeliters = request.getParameter("chargeliters");//
String chargeamt = request.getParameter("chargeamt");//
String gcliters = request.getParameter("gcliters");//
String gcamt = request.getParameter("gcamt");//
String fleetliters = request.getParameter("fleetliters"); //
String fleetamt = request.getParameter("fleetamt"); //
String tappingliters = request.getParameter("tappingliters"); //
String tappingamt = request.getParameter("tappingamt"); //
String hosefillliters = request.getParameter("hosefillliters"); //
String hosefillamt = request.getParameter("hosefillamt"); //
String calibrateliters = request.getParameter("calibrateliters"); //
String calibrateamt = request.getParameter("calibrateamt"); //
String grossliters = request.getParameter("grossliters"); //
String grossamt = request.getParameter("grossamt"); //
String cashdepoamt = request.getParameter("cashdepoamt"); //
String checkdepoamt = request.getParameter("checkdepoamt"); //
String variance = request.getParameter("variance"); //
String cashier = request.getParameter("cashier"); //
String nooftrans = request.getParameter("nooftrans"); //
String tank1level = request.getParameter("tank1level"); //
String tank1liters = request.getParameter("tank1liters"); //
String tank2level = request.getParameter("tank2level"); //
String createdate = request.getParameter("createdate"); //
String userid = request.getParameter("userid"); //
String transmit = request.getParameter("transmit"); //
String transmitdate = request.getParameter("transmitdate"); //
String tank2liters = request.getParameter("tank2liters"); //
String product = request.getParameter("product"); //
//Date dateTemp = new Date(System.currentTimeMillis());
//SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
//String date = dateFormat.format(dateTemp.getTime());
//String description = request.getParameter("description");
//String detail = request.getParameter("detail");
//String category = request.getParameter("category");
//String image = request.getParameter("image");
News n = new News(0, station, date, shift, uprice, cashliters, cashamt, cardliters, cardamt, chargeliters, chargeamt, gcliters, gcamt, fleetliters, fleetamt, tappingliters, tappingamt, hosefillliters, hosefillamt, calibrateliters, calibrateamt, grossliters, grossamt, cashdepoamt, checkdepoamt, variance, cashier, nooftrans, tank1level, tank1liters, tank2level, createdate, userid, transmit, transmitdate, tank2liters, product);
DataAccess da = new DataAccess();
da.addNew(n);
response.sendRedirect("/CRUD_News/AllPost");
%>
</body>
</html>
我不认为这个有什么问题,但在这里。
DataAccess.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dao;
import db.DBUtils;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.News;
/**
*
* @author Thang
*/
public class DataAccess {
public void addNew(News n){
try {
PreparedStatement ps = DBUtils.getPreparedStatement("insert into DailySales values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
//product
ps.setString(1, n.getstation());
ps.setString(2, n.getdate());
ps.setString(3, n.getshift());
ps.setString(4, n.getuprice());
ps.setString(5, n.getcashliters());
ps.setString(6, n.getcashamt());
ps.setString(7, n.getcardliters());
ps.setString(8, n.getcardamt());
ps.setString(9, n.getchargeliters());
ps.setString(10, n.getchargeamt());
ps.setString(11, n.getgcliters());
ps.setString(12, n.getgcamt());
ps.setString(13, n.getfleetliters());
ps.setString(14, n.getfleetamt());
ps.setString(15, n.gettappingliters());
ps.setString(16, n.gettappingamt());
ps.setString(17, n.gethosefillliters());
ps.setString(18, n.gethosefillamt());
ps.setString(19, n.getcalibrateliters());
ps.setString(20, n.getcalibrateamt());
ps.setString(21, n.getgrossliters());
ps.setString(22, n.getgrossamt());
ps.setString(23, n.getcashdepoamt());
ps.setString(24, n.getcheckdepoamt());
ps.setString(25, n.getvariance());
ps.setString(26, n.getcashier());
ps.setString(27, n.getnooftrans());
ps.setString(28, n.gettank1level());
ps.setString(29, n.gettank1liters());
ps.setString(30, n.gettank2level());
ps.setString(31, n.getcreatedate());
ps.setString(32, n.getuserid());
ps.setString(33, n.gettransmit());
ps.setString(34, n.gettransmitdate());
ps.setString(35, n.gettank2liters());
ps.setString(36, n.getproduct());
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
//CHANGE LATER
//CHANGE LATER
//CHANGE LATER
//CHANGE LATER
//CHANGE LATER
//CHANGE LATER//CHANGE LATER
//CHANGE LATER
public static List<News> getAll(){
List<News> ls = new LinkedList<>();
try {
ResultSet rs = DBUtils.getPreparedStatement("select * from DailySales").executeQuery();
while(rs.next()){
News n = new News(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17), rs.getString(18), rs.getString(19), rs.getString(20), rs.getString(21), rs.getString(22), rs.getString(23), rs.getString(24), rs.getString(25), rs.getString(26), rs.getString(27), rs.getString(28), rs.getString(29), rs.getString(30), rs.getString(31), rs.getString(32), rs.getString(33), rs.getString(34), rs.getString(35), rs.getString(36), rs.getString(37));
ls.add(n);
}
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
return ls;
}
public static List<News> getNewById(int id){
List<News> ls = new LinkedList<>();
String sql = "select * from DailySales where dsId = " +id;
try {
ResultSet rs = DBUtils.getPreparedStatement(sql).executeQuery();
while(rs.next()){
News n = new News(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17), rs.getString(18), rs.getString(19), rs.getString(20), rs.getString(21), rs.getString(22), rs.getString(23), rs.getString(24), rs.getString(25), rs.getString(26), rs.getString(27), rs.getString(28), rs.getString(29), rs.getString(30), rs.getString(31), rs.getString(32), rs.getString(33), rs.getString(34), rs.getString(35), rs.getString(36), rs.getString(37));
ls.add(n);
}
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
return ls;
}
public void edit(int id, String station, String description, String date, String shift, String uprice, String cashliters, String cashamt, String cardliters, String cardamt, String chargeliters, String chargeamt, String gcliters, String gcamt, String fleetliters, String fleetamt, String tappingliters, String tappingamt, String hosefillliters, String hosefillamt, String calibrateliters, String calibrateamt, String grossliters, String grossamt, String cashdepoamt, String checkdepoamt, String variance, String cashier, String nooftrans, String tank1level, String tank1liters, String tank2level, String createdate, String userid, String transmit, String transmitdate, String tank2liters, String product){
try {
String sql = "update DailySales SET dsStnCode = ?, dsDate = ?, dsShift = ?, dsUPrice = ?, dsCashLiters = ?, dsCashAmt = ?, dsCardLiters = ?, dsCardAmt = ?, dsChargeLiters = ?, dsChargeAmt = ?, dsGCLiters = ?, dsGCAmt = ?, dsFleetLiters = ?, dsFleetAmt = ?, dsTappingLiters = ?, dsTappingAmt = ?, dsHosefillLiters = ?, dsHoseFillAmt = ?, dsCalibrateLiters = ?, dsCalibrateAmt = ?, dsGrossLiters = ?, dsGrossAmt = ?, dsCashDepoAmt = ?, dsCheckDepoAmt = ?, dsVariance = ?, dsCashier = ?, dsNoOfTrans = ?, dsTank1Level = ?, dsTank1Liters = ?, dsTank2Level = ?, dsCreateDate = ?, dsUserID = ?, dsTransmit = ?, dsTransmitDate = ?, dsTank2Liters = ?, dsProduct = ?" + " where id = ?";
PreparedStatement ps= DBUtils.getPreparedStatement(sql);
ps.setString(1, station);
ps.setString(2, date);
ps.setString(3, shift);
ps.setString(4, uprice);
ps.setString(5, cashliters);
ps.setString(6, cashamt);
ps.setString(7, cardliters);
ps.setString(8, cardamt);
ps.setString(9, chargeliters);
ps.setString(10, chargeamt);
ps.setString(11, gcliters);
ps.setString(12, gcamt);
ps.setString(13, fleetliters);
ps.setString(14, fleetamt);
ps.setString(15, tappingliters);
ps.setString(16, tappingamt);
ps.setString(17, hosefillliters);
ps.setString(18, hosefillamt);
ps.setString(19, calibrateliters);
ps.setString(20, calibrateamt);
ps.setString(21, grossliters);
ps.setString(22, grossamt);
ps.setString(23, cashdepoamt);
ps.setString(24, checkdepoamt);
ps.setString(25, variance);
ps.setString(26, cashier);
ps.setString(27, nooftrans);
ps.setString(28, tank1level);
ps.setString(29, tank1liters);
ps.setString(30, tank2level);
ps.setString(31, createdate);
ps.setString(32, userid);
ps.setString(33, transmit);
ps.setString(34, transmitdate);
ps.setString(35, tank2liters);
ps.setString(36, product);
ps.setInt(37, id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void delete(int id){
try {
String sql = "delete DailySales where dsId = ?";
PreparedStatement ps = DBUtils.getPreparedStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
答案 0 :(得分:0)
我解决了自己的问题,而且这似乎只是我的粗心大意。
<强> AddNew.html 强>
Shift:
<select name="shift">
<option value="World">GY</option>
<option value="World">AM</option>
<option value="Tech">PM</option>
</select><br><br>
我包含了选项价值&#34; World&#34;和&#34; Tech&#34; (这是我在互联网上找到的代码的一部分)即使列的定义&#34; shift&#34;在数据库上是varchar(2)
我很抱歉把时间花在琐碎的事情上。祝你有个美好的一天。