commit
960c1cbb1e
Binary file not shown.
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/servlet-api.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/mysql-connector-java-5.1.39-bin.jar"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/commons-codec-1.10.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/commons-logging-1.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/fluent-hc-4.5.6.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/httpclient-4.5.6.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/httpclient-cache-4.5.6.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/httpclient-win-4.5.6.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/httpcore-4.4.10.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/httpmime-4.5.6.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/jna-4.4.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/httpcomponents-client-4.5.6/lib/jna-platform-4.4.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="E:/OneDrive/share/资源/fastjson-1.2.54.jar"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0 (2)"/>
|
||||||
|
<classpathentry kind="output" path="build/classes"/>
|
||||||
|
</classpath>
|
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>web</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||||
|
<classpathentry kind="src" path=""/>
|
||||||
|
<classpathentry kind="output" path=""/>
|
||||||
|
</classpath>
|
@ -0,0 +1,7 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.7
|
@ -0,0 +1,5 @@
|
|||||||
|
XDOCLETBUILDERACTIVE=true
|
||||||
|
XDOCLETHOME=
|
||||||
|
XDOCLETUSEGLOBAL=true
|
||||||
|
XDOCLETVERSION=1.2.1
|
||||||
|
eclipse.preferences.version=1
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||||
|
<wb-module deploy-name="web">
|
||||||
|
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
|
||||||
|
<property name="context-root" value="web"/>
|
||||||
|
<property name="java-output-path" value="/web/build/classes"/>
|
||||||
|
</wb-module>
|
||||||
|
</project-modules>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<faceted-project>
|
||||||
|
<installed facet="java" version="1.7"/>
|
||||||
|
<installed facet="jst.web" version="3.0"/>
|
||||||
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
|
</faceted-project>
|
@ -0,0 +1 @@
|
|||||||
|
org.eclipse.wst.jsdt.launching.JRE_CONTAINER
|
@ -0,0 +1 @@
|
|||||||
|
Global
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@
|
|||||||
|
User 3
|
||||||
|
UserID NUM
|
||||||
|
openID STRING
|
||||||
|
codeID STRING
|
||||||
|
|
||||||
|
Book 6
|
||||||
|
BookID NUM
|
||||||
|
BookName STRING
|
||||||
|
Author STRING
|
||||||
|
Price NUM
|
||||||
|
Introduce STRING
|
||||||
|
Type NUM
|
||||||
|
|
||||||
|
|
||||||
|
Address 4
|
||||||
|
UserID NUM
|
||||||
|
MessageID NUM
|
||||||
|
telephone NUM
|
||||||
|
Address STRING
|
||||||
|
|
||||||
|
Cart 3
|
||||||
|
UserID NUM
|
||||||
|
BookID NUM
|
||||||
|
Count NUM
|
||||||
|
|
||||||
|
Info 5
|
||||||
|
OrderID NUM
|
||||||
|
BookID NUM
|
||||||
|
Count NUM
|
||||||
|
Status NUM
|
||||||
|
Extra STRING
|
||||||
|
|
||||||
|
Ordered 3
|
||||||
|
OrderID NUM
|
||||||
|
UserID NUM
|
||||||
|
MessageID NUM
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,86 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// 对购物车的操作
|
||||||
|
// 1.查询用户购物车内的书本的数量
|
||||||
|
// 2.在购物表中添加一条条目
|
||||||
|
// 3.在购物车中删除一条条目
|
||||||
|
// 4.在购物车中修改一条条目
|
||||||
|
@WebServlet(name = "AddCart", urlPatterns = {"/AddCart.do"}, loadOnStartup = 2)
|
||||||
|
public class AddCart extends HttpServlet {
|
||||||
|
private boolean _modify(HttpServletRequest request){
|
||||||
|
if(!_delete(request)) return false;
|
||||||
|
return _add(request);
|
||||||
|
}
|
||||||
|
private boolean _add(HttpServletRequest request){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
String BookID = request.getParameter("BookID");
|
||||||
|
String Count = request.getParameter("Count");
|
||||||
|
if(sqlfilter.isNumber(UserID) && sqlfilter.isNumber(BookID) &&
|
||||||
|
sqlfilter.isNumber(Count)){
|
||||||
|
ArrayList<String> add = new ArrayList<>();
|
||||||
|
add.add(UserID);
|
||||||
|
add.add(BookID);
|
||||||
|
add.add(Count);
|
||||||
|
String sql = Readclass.getInsertString("Cart",add);
|
||||||
|
return ExecuteUpd.execute(request,sql);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private boolean _delete(HttpServletRequest request){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
String BookID = request.getParameter("BookID");
|
||||||
|
if(sqlfilter.isNumber(UserID) && sqlfilter.isNumber(BookID)){
|
||||||
|
String sql = "delete from Cart where UserID="+ UserID +
|
||||||
|
" and BookID=" + BookID;
|
||||||
|
return ExecuteUpd.execute(request,sql);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String action = request.getParameter("action");
|
||||||
|
if(action == null){
|
||||||
|
response.setStatus(400);
|
||||||
|
}else if(action.equals("Modify")) {
|
||||||
|
boolean flag=_modify(request);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}else if(action.equals("Add")){
|
||||||
|
boolean flag=_add(request);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}else if(action.equals("Delete")){
|
||||||
|
boolean flag=_delete(request);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}else if(action.equals("getinfo")){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
if (sqlfilter.isNumber(UserID)) {
|
||||||
|
String sql = "select Book.BookID,Count,BookName,Price from Cart " +
|
||||||
|
"join Book on Book.BookID=Cart.BookID "+
|
||||||
|
"where UserID=" + UserID;
|
||||||
|
System.err.println(sql);
|
||||||
|
HashMap<String,String> names = new HashMap<>();
|
||||||
|
names.put("BookName","BookName");
|
||||||
|
names.put("BookID","BookID");
|
||||||
|
names.put("Count","Count");
|
||||||
|
names.put("Price","Price");
|
||||||
|
GetJson.Getinfo(request,response,sql,names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request,response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// 这个界面的作用是对于该用户的地址进行管理
|
||||||
|
// 添加一个,删除一个,或者修改一个
|
||||||
|
// 如果修改失败,我们返回一个
|
||||||
|
@WebServlet(name = "Address", urlPatterns = {"/Address.do"}, loadOnStartup = 2)
|
||||||
|
public class Address extends HttpServlet {
|
||||||
|
private boolean modify(HttpServletRequest request){
|
||||||
|
if(!delete(request)) return false;
|
||||||
|
return add(request);
|
||||||
|
}
|
||||||
|
private boolean add(HttpServletRequest request){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
String telephone = request.getParameter("telephone");
|
||||||
|
String Address = request.getParameter("Address");
|
||||||
|
boolean flag = false;
|
||||||
|
if(sqlfilter.isNumber(UserID) && telephone !=null & Address !=null) {
|
||||||
|
flag = true;
|
||||||
|
telephone = sqlfilter.filter(telephone);
|
||||||
|
Address = sqlfilter.filter(Address);
|
||||||
|
String tmp = "select max(MessageID)+1 as ret from Address where UserID=" + UserID;
|
||||||
|
Statement state = (Statement) (request.getServletContext().getAttribute("state"));
|
||||||
|
try {
|
||||||
|
ResultSet Result = state.executeQuery(tmp);
|
||||||
|
String MessageID = "1";
|
||||||
|
while (Result.next()) {
|
||||||
|
MessageID = Result.getString("ret");
|
||||||
|
}
|
||||||
|
ArrayList<String> add = new ArrayList<>();
|
||||||
|
telephone = sqlfilter.filter(telephone);
|
||||||
|
Address = sqlfilter.filter(Address);
|
||||||
|
add.add(UserID);
|
||||||
|
add.add(MessageID);
|
||||||
|
add.add(telephone);
|
||||||
|
add.add(Address);
|
||||||
|
String sql = Readclass.getInsertString("Address", add);
|
||||||
|
if(!ExecuteUpd.execute(request,sql)) flag = false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
flag = false;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
private boolean delete(HttpServletRequest request){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
String MessageID = request.getParameter("MessageID");
|
||||||
|
if(sqlfilter.isNumber(UserID) && sqlfilter.isNumber(MessageID)){
|
||||||
|
String sql = "delete from Address where UserID="+ UserID +
|
||||||
|
" and MessageID=" + MessageID;
|
||||||
|
return ExecuteUpd.execute(request,sql);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String action = request.getParameter("action");
|
||||||
|
if(action == null){
|
||||||
|
response.setStatus(400);
|
||||||
|
}else if(action.equals("Modify")) {
|
||||||
|
boolean flag=modify(request);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}else if(action.equals("Add")){
|
||||||
|
boolean flag=add(request);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}else if(action.equals("Delete")){
|
||||||
|
boolean flag=delete(request);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}else if(action.equals("getinfo")){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
if (sqlfilter.isNumber(UserID)) {
|
||||||
|
String sql = "select MessageID,telephone,Address,MessageID from Address where UserID=" + UserID;
|
||||||
|
HashMap<String,String> names = new HashMap<>();
|
||||||
|
names.put("MessageID","MessageID");
|
||||||
|
names.put("telephone","telephone");
|
||||||
|
names.put("Address","Address");
|
||||||
|
GetJson.Getinfo(request,response,sql,names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request,response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// 首先明确我们这个目的是目标页面的分类功能,根据用户所需要返回所有该类别的图书
|
||||||
|
@WebServlet(name = "BookInfo", urlPatterns = {"/BookInfo.do"}, loadOnStartup = 2)
|
||||||
|
public class BookInfo extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request,
|
||||||
|
HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
if (Authentication.islegal(request)) {
|
||||||
|
String bookid = request.getParameter("bookid");
|
||||||
|
String fuzzy = request.getParameter("fuzzy");
|
||||||
|
String bookname = request.getParameter("bookname");
|
||||||
|
if(bookname!=null) bookname = sqlfilter.filter(bookname);
|
||||||
|
boolean isfuzzy = false;
|
||||||
|
if(fuzzy != null && fuzzy.equals("true") && bookname != null) isfuzzy = true;
|
||||||
|
// 防止sql注入
|
||||||
|
if (isfuzzy || sqlfilter.isNumber(bookid)) {
|
||||||
|
String sql = "";
|
||||||
|
if(!isfuzzy) sql = "select * from Book where BookId = " + bookid;
|
||||||
|
else sql = "select * from Book where BookName like '"+bookname+"%'";
|
||||||
|
HashMap<String,String> names = new HashMap<>();
|
||||||
|
names.put("BookID","BookId");
|
||||||
|
names.put("BookName","BookName");
|
||||||
|
names.put("Author","Author");
|
||||||
|
names.put("Price","Price");
|
||||||
|
names.put("Introduce","Introduce");
|
||||||
|
GetJson.Getinfo(request,response,sql,names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void doGet(HttpServletRequest request,
|
||||||
|
HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
doPost(request,response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@WebServlet(name = "Buy" ,urlPatterns = {"/Buy.do"}, loadOnStartup = 2)
|
||||||
|
// 实现从图书详情界面直接修改
|
||||||
|
// 写触发器?不存在的
|
||||||
|
// 错了就错了,不管了
|
||||||
|
public class Buy extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
String MessageID = request.getParameter("MessageID");
|
||||||
|
String OrderID = String.valueOf(++LoginDatabase.SerialID);
|
||||||
|
String BookID = request.getParameter("BookID");
|
||||||
|
String Count = request.getParameter("Count");
|
||||||
|
String Status = "1";
|
||||||
|
String Extra = "未出货";
|
||||||
|
//向两张表都插入数据
|
||||||
|
if(sqlfilter.isNumber(UserID) && sqlfilter.isNumber(MessageID) &&
|
||||||
|
sqlfilter.isNumber(BookID) && sqlfilter.isNumber(Count)){
|
||||||
|
ArrayList<String> order = new ArrayList<>();
|
||||||
|
ArrayList<String> info = new ArrayList<>();
|
||||||
|
/************************/
|
||||||
|
order.add(OrderID);
|
||||||
|
order.add(UserID);
|
||||||
|
order.add(MessageID);
|
||||||
|
/************************/
|
||||||
|
info.add(OrderID);
|
||||||
|
info.add(BookID);
|
||||||
|
info.add(Count);
|
||||||
|
info.add(Status);
|
||||||
|
info.add(Extra);
|
||||||
|
/************************/
|
||||||
|
String sql1 = Readclass.getInsertString("Ordered",order);
|
||||||
|
String sql2 = Readclass.getInsertString("Info",info);
|
||||||
|
boolean flag = (ExecuteUpd.execute(request,sql1) && ExecuteUpd.execute(request,sql2));
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request,response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// 检查该用户处于某一个状态下的所有订单
|
||||||
|
// 要注意的就是保证该用户账户的合法性
|
||||||
|
@WebServlet(name = "CheckOrders", urlPatterns = {"/CheckOrders.do"}, loadOnStartup = 2)
|
||||||
|
public class CheckOrders extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String UserID = request.getParameter("UserID");
|
||||||
|
String Status = request.getParameter("status");
|
||||||
|
if(sqlfilter.isNumber(UserID) && sqlfilter.isNumber(Status)) {
|
||||||
|
String sql = "select Ordered.OrderID,Book.BookID,BookName,Count,Extra,telephone,Address,Ordered.MessageID " +
|
||||||
|
"from Ordered join Address on Address.UserID = Ordered.UserID and Address.MessageID " +
|
||||||
|
"= Ordered.MessageID join Info on Ordered.OrderID = Info.OrderID " +
|
||||||
|
"join Book on Book.BookID = Info.BookID " +
|
||||||
|
"where status =" + Status +
|
||||||
|
" and Ordered.UserID=" + UserID;
|
||||||
|
HashMap<String,String> names = new HashMap<>();
|
||||||
|
names.put("OrderID","OrderID");
|
||||||
|
names.put("BookID","BookID");
|
||||||
|
names.put("BookName","BookName");
|
||||||
|
names.put("Count","Count");
|
||||||
|
names.put("Extra","Extra");
|
||||||
|
names.put("telephone","telephone");
|
||||||
|
names.put("Address","Address");
|
||||||
|
names.put("MessageID","MessageID");
|
||||||
|
GetJson.Getinfo(request,response,sql,names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// 首先明确我们这个目的是目标页面的分类功能,根据用户所需要返回所有该类别的图书
|
||||||
|
@WebServlet(name = "Classify", urlPatterns = {"/Classify.do"}, loadOnStartup = 2)
|
||||||
|
public class Classify extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String booktype = request.getParameter("booktype");
|
||||||
|
// 防止sql注入
|
||||||
|
if(sqlfilter.isNumber(booktype)) {
|
||||||
|
String sql = "select * from Book where Type = " + booktype;
|
||||||
|
HashMap<String,String> names = new HashMap<>();
|
||||||
|
names.put("BookID","BookID");
|
||||||
|
names.put("BookName","BookName");
|
||||||
|
GetJson.Getinfo(request,response,sql,names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request,response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class ExecuteUpd {
|
||||||
|
public static boolean execute(HttpServletRequest request, String QueryString){
|
||||||
|
ServletContext context = request.getServletContext();
|
||||||
|
Statement state = (Statement)context.getAttribute("state");
|
||||||
|
boolean flag = true;
|
||||||
|
try{
|
||||||
|
state.execute(QueryString);
|
||||||
|
}catch (Exception e){
|
||||||
|
flag = false;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// 得到首页信息
|
||||||
|
@WebServlet(name = "GetFrontInfo", urlPatterns = {"/GetFrontInfo.do"}, loadOnStartup = 2)
|
||||||
|
public class GetFrontInfo extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
// 其实我们只要返回BookID对应的名称就可以了
|
||||||
|
// 然后根据书本名字就可以在对应的目录
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String sql = "select BookID,BookName,Introduce from Book where BookID in (select BookID from Display)";
|
||||||
|
HashMap<String,String> names = new HashMap<>();
|
||||||
|
names.put("BookID","BookID");
|
||||||
|
names.put("BookName","BookName");
|
||||||
|
names.put("Introduce","Introduce");
|
||||||
|
GetJson.Getinfo(request,response,sql,names);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
public ArrayList<String> key=new ArrayList<String>();
|
||||||
|
public ArrayList<String> type=new ArrayList<String>();
|
||||||
|
public int size=0;
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import javax.servlet.ServletConfig;
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
// 连接数据库的我们是服务开始的时候
|
||||||
|
@WebServlet(name = "LoginDatabase", urlPatterns = {"/Startup.do"}, loadOnStartup = 1)
|
||||||
|
public class LoginDatabase extends HttpServlet {
|
||||||
|
private String mysql, url, user, passwd;
|
||||||
|
private Connection conn;
|
||||||
|
private Statement state;
|
||||||
|
public static int SerialID ;
|
||||||
|
public static HashMap<String,Item> Map=new HashMap<>();
|
||||||
|
private void initDataBase() throws ClassNotFoundException, SQLException {
|
||||||
|
Class.forName(mysql);
|
||||||
|
conn = DriverManager.getConnection(url,user,passwd);
|
||||||
|
state = conn.createStatement();
|
||||||
|
ResultSet rs = state.executeQuery("select max(OrderID) as num from Ordered");
|
||||||
|
SerialID = 1;
|
||||||
|
while(rs.next()){
|
||||||
|
SerialID = rs.getInt("num") + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void closeDataBase(){
|
||||||
|
if(state != null) {
|
||||||
|
try{
|
||||||
|
state.close();
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(conn != null) {
|
||||||
|
try{
|
||||||
|
conn.close();
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void init(ServletConfig config) throws ServletException{
|
||||||
|
super.init(config);
|
||||||
|
Readclass.init(getServletContext());
|
||||||
|
ServletContext context=getServletContext();
|
||||||
|
mysql = context.getInitParameter("mysql");
|
||||||
|
url = context.getInitParameter("url");
|
||||||
|
user = context.getInitParameter("user");
|
||||||
|
passwd = context.getInitParameter("passwd");
|
||||||
|
try{
|
||||||
|
initDataBase();
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println("Successful Connected!");
|
||||||
|
context.setAttribute("conn",conn);
|
||||||
|
context.setAttribute("state",state);
|
||||||
|
}
|
||||||
|
public void destroy(){
|
||||||
|
closeDataBase();
|
||||||
|
super.destroy();
|
||||||
|
}
|
||||||
|
public void doGet(HttpServletRequest request,
|
||||||
|
HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
response.sendRedirect("/index.html");
|
||||||
|
}
|
||||||
|
public void doPost(HttpServletRequest request,
|
||||||
|
HttpServletResponse response)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
doGet(request, response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
//这个作用是改变一个订单的状态
|
||||||
|
// 我们这里订单状态定义了四个状态
|
||||||
|
// 1 待付款
|
||||||
|
// 2 待发货
|
||||||
|
// 3 待收货
|
||||||
|
// 4 收货完成
|
||||||
|
@WebServlet(name = "ModifyStatus", urlPatterns = {"/ModifyStatus.do"}, loadOnStartup = 2)
|
||||||
|
public class ModifyStatus extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
if(Authentication.islegal(request)){
|
||||||
|
String OrderID = request.getParameter("OrderID");
|
||||||
|
String Status = request.getParameter("status");
|
||||||
|
String Extra = request.getParameter("Extra");
|
||||||
|
if(Extra == null) Extra = "";
|
||||||
|
// 并且我们这里要做一个验证保证用户的身份正确
|
||||||
|
if(sqlfilter.isNumber(OrderID) && sqlfilter.islegalStatus(Status)){
|
||||||
|
Extra = sqlfilter.filter(Extra);
|
||||||
|
String sql = "update Info set Status='"+ Status + "'" +
|
||||||
|
",Extra='" + Extra + "' where OrderID=" + OrderID;
|
||||||
|
boolean flag = ExecuteUpd.execute(request,sql);
|
||||||
|
if(!flag) response.setStatus(400);
|
||||||
|
else response.setStatus(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doPost(request, response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Readclass {
|
||||||
|
public static void init(ServletContext context){
|
||||||
|
try{
|
||||||
|
Scanner fin=new Scanner(context.getResourceAsStream("WEB-INF/variable"));
|
||||||
|
while(fin.hasNext()){
|
||||||
|
String className=fin.next();
|
||||||
|
int count=fin.nextInt();
|
||||||
|
Item item=new Item();
|
||||||
|
item.size=count;
|
||||||
|
for(int i=0;i<count;i++){
|
||||||
|
String name=fin.next();
|
||||||
|
String type=fin.next();
|
||||||
|
item.key.add(name);
|
||||||
|
item.type.add(type);
|
||||||
|
}
|
||||||
|
LoginDatabase.Map.put(className,item);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
System.err.println("配置文件错误");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//方便sql 语句插入的操作
|
||||||
|
public static ArrayList<String> getWord(String table, ArrayList<String> value){
|
||||||
|
Item item=LoginDatabase.Map.get(table);
|
||||||
|
ArrayList<String> arrayList=new ArrayList<String>();
|
||||||
|
for(int i=0;i<item.size;i++){
|
||||||
|
String type=item.type.get(i);
|
||||||
|
String val=value.get(i);
|
||||||
|
if(val.equals("NULL")) {
|
||||||
|
arrayList.add("NULL");
|
||||||
|
}else if(type.equals("NUM")){
|
||||||
|
arrayList.add(sqlfilter.filter(val));
|
||||||
|
}else if(type.equals("STRING")){
|
||||||
|
arrayList.add("'"+sqlfilter.filter(val)+"'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
public static String getInsertString(String table, ArrayList<String> arrayList){
|
||||||
|
int sz = arrayList.size();
|
||||||
|
ArrayList<String> ins = getWord(table,arrayList);
|
||||||
|
StringBuffer sb = new StringBuffer("insert into ");
|
||||||
|
sb.append(table);
|
||||||
|
sb.append(" values");
|
||||||
|
sb.append(" (");
|
||||||
|
for(int i=0;i<sz;i++){
|
||||||
|
sb.append(ins.get(i));
|
||||||
|
if(i != sz-1) sb.append(",");
|
||||||
|
}
|
||||||
|
sb.append(")");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package WeChat;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.annotation.WebServlet;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@WebServlet(name = "initUser", urlPatterns = "/InitUser.do", loadOnStartup = 2)
|
||||||
|
public class initUser extends HttpServlet {
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
try{
|
||||||
|
Authentication.init(request,response);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
doGet(request,response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
User 3
|
||||||
|
UserID NUM
|
||||||
|
openID STRING
|
||||||
|
codeID STRING
|
||||||
|
|
||||||
|
Book 6
|
||||||
|
BookID NUM
|
||||||
|
BookName STRING
|
||||||
|
Author STRING
|
||||||
|
Price NUM
|
||||||
|
Introduce STRING
|
||||||
|
Type NUM
|
||||||
|
|
||||||
|
|
||||||
|
Address 4
|
||||||
|
UserID NUM
|
||||||
|
MessageID NUM
|
||||||
|
telephone NUM
|
||||||
|
Address STRING
|
||||||
|
|
||||||
|
Cart 3
|
||||||
|
UserID NUM
|
||||||
|
BookID NUM
|
||||||
|
Count NUM
|
||||||
|
|
||||||
|
Info 5
|
||||||
|
OrderID NUM
|
||||||
|
BookID NUM
|
||||||
|
Count NUM
|
||||||
|
Status NUM
|
||||||
|
Extra STRING
|
||||||
|
|
||||||
|
Ordered 3
|
||||||
|
OrderID NUM
|
||||||
|
UserID NUM
|
||||||
|
MessageID NUM
|
Loading…
Reference in new issue