📄 bookmaint_jsp.java
字号:
String id = "";
String val = "";
java.util.StringTokenizer LOV = new java.util.StringTokenizer( sLOV, ";", true);
int i = 0;
String old = ";";
while ( LOV.hasMoreTokens() ) {
id = LOV.nextToken();
if ( ! old.equals(";") && ( id.equals(";") ) ) {
id = LOV.nextToken();
}
else {
if ( old.equals(";") && ( id.equals(";") ) ) {
id = "";
}
}
if ( ! id.equals("") ) { old = id; }
i++;
if (LOV.hasMoreTokens()) {
val = LOV.nextToken();
if ( ! old.equals(";") && (val.equals(";") ) ) {
val = LOV.nextToken();
}
else {
if (old.equals(";") && (val.equals(";"))) {
val = "";
}
}
if ( val.equals(";") ) { val = ""; }
if ( ! val.equals("")) { old = val; }
i++;
}
if ( id.compareTo( selectedValue ) == 0 ) {
sSel = "SELECTED";
}
else {
sSel = "";
}
slOptions += "<option value=\""+id+"\" "+sSel+">"+val+"</option>";
}
if ( ( i % 2 ) == 0 ) sOptions += slOptions;
return sOptions;
}
String getValFromLOV( String selectedValue , String sLOV) {
String sRes = "";
String id = "";
String val = "";
java.util.StringTokenizer LOV = new java.util.StringTokenizer( sLOV, ";", true);
int i = 0;
String old = ";";
while ( LOV.hasMoreTokens() ) {
id = LOV.nextToken();
if ( ! old.equals(";") && ( id.equals(";") ) ) {
id = LOV.nextToken();
}
else {
if ( old.equals(";") && ( id.equals(";") ) ) {
id = "";
}
}
if ( ! id.equals("") ) { old = id; }
i++;
if (LOV.hasMoreTokens()) {
val = LOV.nextToken();
if ( ! old.equals(";") && (val.equals(";") ) ) {
val = LOV.nextToken();
}
else {
if (old.equals(";") && (val.equals(";"))) {
val = "";
}
}
if ( val.equals(";") ) { val = ""; }
if ( ! val.equals("")) { old = val; }
i++;
}
if ( id.compareTo( selectedValue ) == 0 ) {
sRes = val;
}
}
return sRes;
}
String checkSecurity(int iLevel, javax.servlet.http.HttpSession session, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request){
try {
Object o1 = session.getAttribute("UserID");
Object o2 = session.getAttribute("UserRights");
boolean bRedirect = false;
if ( o1 == null || o2 == null ) { bRedirect = true; }
if ( ! bRedirect ) {
if ( (o1.toString()).equals("")) { bRedirect = true; }
else if ( (new Integer(o2.toString())).intValue() < iLevel) { bRedirect = true; }
}
if ( bRedirect ) {
response.sendRedirect("Login.jsp?querystring=" + toURL(request.getQueryString()) + "&ret_page=" + toURL(request.getRequestURI()));
return "sendRedirect";
}
}
catch(Exception e){};
return "";
}
static final String sFileName = "BookMaint.jsp";
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;
break;
}
if ( sBookErr.length() > 0 ) return sBookErr;
try {
// Execute SQL statement
stat.executeUpdate(sSQL);
}
catch(java.sql.SQLException e) {
sBookErr = e.toString(); return (sBookErr);
}
try {
if ( stat != null ) stat.close();
if ( conn != null ) conn.close();
}
catch ( java.sql.SQLException ignore ) {}
response.sendRedirect (sActionFileName + sParams);
return "sendRedirect";
}
catch (Exception e) {out.println(e.toString()); }
return (sBookErr);
}
void Book_Show(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sBookErr, String sForm, String sAction, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException {
try {
String sSQL="";
String sQueryString = "";
String sPage = "";
String sWhere = "";
String transitParams = "";
String transitParamsHidden = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -