📄 bookmaint.jsp
字号:
<%@ page import="function.*" contentType="text/html;charset=gb2312" %>
<%@ include file="Common.jsp" %><%!
static final String sFileName = "BookMaint.jsp";
%><%
String cSec = checkSecurity(2, session, response, request);
if ("sendRedirect".equals(cSec) ) return;
boolean bDebug = false;
String sAction = getParam( request, "FormAction");
String sForm = getParam( request, "FormName");
String sBookErr = "";
java.sql.Connection conn = null;
java.sql.Statement stat = null;
String sErr = loadDriver();
conn = cn();
stat = conn.createStatement();
if ( ! sErr.equals("") ) {
try {
out.println(sErr);
}
catch (Exception e) {}
}
if ( sForm.equals("Book") ) {
sBookErr = BookAction(request, response, session, out, sAction, sForm, conn, stat);
if ( "sendRedirect".equals(sBookErr)) return;
}
%>
<html>
<head>
<title>Book Store</title>
<meta name="GENERATOR" content="YesSoftware CodeCharge v.1.2.0 / JSP.ccp build 05/21/2001"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body style="background-color: #FFFFFF; color: #000000; font-family: Arial, Tahoma, Verdana, Helveticabackground-color: #FFFFFF; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
<jsp:include page="Header.jsp" flush="true"/>
<table>
<tr>
<td valign="top">
<% Book_Show(request, response, session, out, sBookErr, sForm, sAction, conn, stat); %>
<SCRIPT Language="JavaScript">
if (document.forms["Book"])
document.Book.onsubmit=delconf;
function delconf() {
if (document.Book.FormAction.value == 'delete')
return confirm('Delete record?');
}
</SCRIPT>
</td>
</tr>
</table>
<jsp:include page="Footer.jsp" flush="true"/>
</body>
</html>
<%%>
<%
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
%>
<%!
String BookAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sAction, String sForm, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException {
String sBookErr ="";
try {
if (sAction.equals("")) return "";
String sSQL="";
String transitParams = "";
String primaryKeyParams = "";
String sQueryString = "";
String sPage = "";
String sParams = "";
String sActionFileName = "AdminBooks.jsp";
String sWhere = " ";
boolean bErr = false;
long iCount = 0;
sParams = "?";
sParams += "category_id=" + toURL(getParam( request, "Trn_category_id"));
String pPKitem_id = "";
if (sAction.equalsIgnoreCase("cancel") ) {
try {
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
}
catch ( java.sql.SQLException ignore ) {}
response.sendRedirect (sActionFileName + sParams);
return "sendRedirect";
}
final int iinsertAction = 1;
final int iupdateAction = 2;
final int ideleteAction = 3;
int iAction = 0;
if ( sAction.equalsIgnoreCase("insert") ) { iAction = iinsertAction; }
if ( sAction.equalsIgnoreCase("update") ) { iAction = iupdateAction; }
if ( sAction.equalsIgnoreCase("delete") ) { iAction = ideleteAction; }
// Create WHERE statement
if ( iAction == iupdateAction || iAction == ideleteAction ) {
pPKitem_id = getParam( request, "PK_item_id");
if ( isEmpty(pPKitem_id)) return sBookErr;
sWhere = "item_id=" + toSQL(pPKitem_id, adNumber);
}
String fldname="";
String fldauthor="";
String fldcategory_id="";
String fldprice="";
String fldproduct_url="";
String fldimage_url="";
String fldnotes="";
String fldis_recommended="";
String flditem_id="";
// Load all form fields into variables
fldname = getParam(request, "name");
fldauthor = getParam(request, "author");
fldcategory_id = getParam(request, "category_id");
fldprice = getParam(request, "price");
fldproduct_url = getParam(request, "product_url");
fldimage_url = getParam(request, "image_url");
fldnotes = getParam(request, "notes");
fldis_recommended = getCheckBoxValue(getParam( request, "is_recommended"), "1", "0", adNumber);
// Validate fields
if ( iAction == iinsertAction || iAction == iupdateAction ) {
if ( isEmpty(fldname) ) {
sBookErr = sBookErr + "The value in field Title is required.<br>";
}
if ( isEmpty(fldcategory_id) ) {
sBookErr = sBookErr + "The value in field Category is required.<br>";
}
if ( isEmpty(fldprice) ) {
sBookErr = sBookErr + "The value in field Price is required.<br>";
}
if ( ! isNumber(fldcategory_id)) {
sBookErr = sBookErr + "The value in field Category is incorrect.<br>";
}
if ( ! isNumber(fldprice)) {
sBookErr = sBookErr + "The value in field Price is incorrect.<br>";
}
if (sBookErr.length() > 0 ) {
return (sBookErr);
}
}
sSQL = "";
// Create SQL statement
switch (iAction) {
case iinsertAction :
sSQL = "insert into items (" +
"name," +
"author," +
"category_id," +
"price," +
"product_url," +
"image_url," +
"notes," +
"is_recommended)" +
" values (" +
toSQL(fldname, adText) + "," +
toSQL(fldauthor, adText) + "," +
toSQL(fldcategory_id, adNumber) + "," +
toSQL(fldprice, adNumber) + "," +
toSQL(fldproduct_url, adText) + "," +
toSQL(fldimage_url, adText) + "," +
toSQL(fldnotes, adText) + "," +
fldis_recommended + ")";
break;
case iupdateAction:
sSQL = "update items set " +
"name=" + toSQL(fldname, adText) +
",author=" + toSQL(fldauthor, adText) +
",category_id=" + toSQL(fldcategory_id, adNumber) +
",price=" + toSQL(fldprice, adNumber) +
",product_url=" + toSQL(fldproduct_url, adText) +
",image_url=" + toSQL(fldimage_url, adText) +
",notes=" + toSQL(fldnotes, adText) +
",is_recommended=" + fldis_recommended;
sSQL = sSQL + " where " + sWhere;
break;
case ideleteAction:
sSQL = "delete from items where " + sWhere;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -