基于javaweb+mysql的jsp+servlet汽配商城系统(java+servlet+javascript+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet汽配商城系统(java+servlet+javascript+jsp+mysql)
项目介绍
管理员角色包含以下功能: 修改管理员信息,订单管理,客户管理,鞋子管理,类目管理等功能。
用户角色包含以下功能: 查看首页,用户登录,修改个人信息,按分类查看鞋子,查看热销鞋子,查看新鞋子·,查看商品详情,查看我的购物车,提交订单,查看我的订单等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本;
技术栈
HTML+CSS+JavaScript+jsp+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/login.jsp 登录
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class Message extends HttpServlet {
/**
* Constructor of the object.
*/
public Message() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
sql += ") values(";
rs.close();
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
Enumeration enumeration = request.getParameterNames();
String names = ",";
while (enumeration.hasMoreElements()) {
names += enumeration.nextElement().toString() + ",";
}
try {
Statement st = conn.createStatement();
for (String str : collist) {
if (names.indexOf("," + str + ",") > -1) {
String[] values = request.getParameterValues(str);
String value = "";
for (String vstr : values) {
if (vstr == null) vstr = "";
if (vstr.equals("null")) vstr = "";
if (vstr.trim().equals("")) continue;
if (request.getParameter(vstr) != null && !"".equals(request.getParameter(vstr)) && request.getParameter("dk-" + str + "-value") != null) {
String dkv = request.getParameter(vstr);
String dknamevalue = request.getParameter("dk-" + str + "-value");
vstr += " - " + dknamevalue + ":" + dkv;
}
value += vstr + " ~ ";
}
if (value == null) value = "";
if (value.equals("null")) value = "";
if (value.length() > 0) value = value.substring(0, value.length() - 3);
if (typemap.get(str + "---").equals("int")) {
sql += (value.equals("") ? -10 : value) + ",";
} else {
sql += "'" + (value.equals("null") ? "" : value) + "',";
}
} else {
if (typemap.get(str + "---").equals("int")) {
sql += (extmap.get(str) == null ? "" : extmap.get(str)) + ",";
} else {
sql += "'" + (extmap.get(str) == null ? "" : extmap.get(str)) + "',";
}
}
}
ret.append(getDateStr());
ret.append(rand.substring(0,6));
return ret.toString();
}
public static String getImgUpInfoExt(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txtext height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename\" id=\"filename\" value=\"\" />";
return jscode;
}
public static String getImgUpInfo(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txt height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename\" id=\"filename\" value=\"\" />";
return jscode;
}
public static String getImgUpInfo2(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg2()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txt2 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename2\" id=\"filename2\" value=\"\" />";
return jscode;
}
public static String getImgUpInfo3(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg3()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txt3 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename3\" id=\"filename3\" value=\"\" />";
return jscode;
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CommDAO dao = new CommDAO();
String uname = request.getParameter("uname");
int i = dao.getInt("select count(*) from buser where uname='"+uname+"'");
String yn = "n";
if(i>0)
{
yn = "y";
}
PrintWriter wrt = null;
try {
wrt = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wrt.write(yn);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
new Info().delPic(request.getRealPath("/upfile/")+"/", filename);
} catch (Exception e) {
e.printStackTrace();
}finally{
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class TestUpload extends HttpServlet {
/**
* Constructor of the object.
*/
public TestUpload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = Info.generalFileName(fullFile.getName());
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
fileItem.write(newFile);
} catch (Exception e) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploadimg2.jsp?filename="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploadimg3"))
{
try {
String filename="";
request.setCharacterEncoding("utf-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
return jscode;
}
public static String getImgUpInfo3(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg3()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txt3 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename3\" id=\"filename3\" value=\"\" />";
return jscode;
}
public static String getImgUpInfo4(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg4()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txt4 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename4\" id=\"filename4\" value=\"\" />";
return jscode;
}
public static String getImgUpInfo5(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg5()\" src=\"/jsp_qipei_shop/js/nopic.jpg\" id=txt5 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename5\" id=\"filename5\" value=\"\" />";
return jscode;
}
public static String fck(int height,String content)
{
String jscode = "<TEXTAREA name=\"content\" id=\"content\">"+content+"</TEXTAREA>";
jscode+="<script language=\"javascript\">";
jscode+="function fckinit()";
jscode+="{";
jscode+=" var of = new FCKeditor(\"content\");";
jscode+="of.BasePath=\"/jsp_qipei_shop/fckeditor/\";";
jscode+="of.Height = \""+height+"\";";
jscode+="of.ToolbarSet=\"Default\";";
jscode+="of.ReplaceTextarea();";
jscode+="}";
jscode+="fckinit();";
jscode+="</script>";
return jscode;
String checkbox="";
int i=0;
for(HashMap permap:new CommDAO().select("select * from "+tablename+" where "+where+" order by id desc")){
String optionstr = "";
for(String str:zdname.split(";"))
{
String zdstr = str.split("~")[0];
String zdnamestr = str.split("~")[1].equals("无名")?"":(str.split("~")[1]+":");
optionstr+=zdnamestr+permap.get(zdstr)+" - ";
}
if(optionstr.length()>0)optionstr=optionstr.substring(0,optionstr.length()-3);
String nbs = "";
if(i>0)nbs=" ";
checkbox+="<label>"+nbs+"<input type='checkbox' name='"+name+"' value=\""+optionstr+"\">"+optionstr+"</label> \n";
checkbox+="<label> - "+nstr+" <input type='text' size='5' name='"+optionstr+"' value=\"\"> "+danwei+" </label><br />\n";
i++;
}
checkbox+="<input type=hidden name='"+name+"' value='' /><input type=hidden name='dk-"+name+"-value' value='"+nstr+"' />";
return checkbox;
}
public static String getFileUpInfo()
{
String jscode = "";
jscode+="<font οnclick=\"uploaddoc()\" src=\"js/nopic.jpg\" style='cursor:hand' id=txt >点击此处上传</font>";
jscode+=" <input type=text readonly style='border:0px' size=30 name=\"docname\" id=\"docname\" value=\"\" />";
return jscode;
}
public static String getFileUpInfo2()
{
String jscode = "";
jscode+="<font οnclick=\"uploaddoc2()\" src=\"js/nopic.jpg\" style='cursor:hand' id=filetxt2 >点击此处上传</font>";
jscode+=" <input type=text readonly style='border:0px' size=30 name=\"docname2\" id=\"docname2\" value=\"\" />";
return jscode;
}
public static String getFileUpInfo3()
{
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = fullFile.getName();
filename = filename.substring(0,filename.lastIndexOf("."))+"-"+Info.getDateStr().replaceAll("-","").replaceAll(" ","").replaceAll(":","")+filename.substring(filename.lastIndexOf("."));
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
fileItem.write(newFile);
} catch (Exception e) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploaddoc3.jsp?docname="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploaddoc4"))
{
try {
String filename="";
request.setCharacterEncoding("utf-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
}
}
}
}
sql = sql.substring(0, sql.length() - 1);
sql += " where id=" + request.getParameter("id");
System.out.println(sql);
Statement st1 = conn.createStatement();
st1.execute(sql);
st1.close();
rs.close();
st.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
String str = "";
if (!reflush)
str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
str += "<script language=javascript>\n";
if (alert) {
str += "alert('操作成功');\n";
}
if (reflush) {
str += "parent.location=parent.location;\n";
}
str += "</script>\n";
PrintWriter wrt = null;
try {
//request.get
wrt = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wrt.write(str);
}
return "";
}
public int getInt(String sql) {
System.out.println(sql);
int i = 0;
*/
public Upass() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uname = request.getParameter("uname");
String utype = request.getParameter("utype");
String upass = request.getParameter("pass");
CommDAO dao = new CommDAO();
dao.commOper("update buser set upass='"+upass+"' where uname='"+uname+"'");
if(utype.equals("0"))
{
public String getInfo() {
return info;
}
}
public class Upsp extends HttpServlet {
/**
* Constructor of the object.
*/
public Upsp() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
}
public void gor(String url,HttpServletRequest request, HttpServletResponse response)
{
try {
response.sendRedirect(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
HashMap user = (HashMap)session.getAttribute("user");
String ac = request.getParameter("ac");
if(ac==null)ac="";
CommDAO dao = new CommDAO();
String date = Info.getDateStr();
String today = date.substring(0,10);
String tomonth = date.substring(0,7);
if(ac.equals("addpinlun"))
{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String content = request.getParameter("pcontent");
String proid = request.getParameter("proid");
String sql = "insert into pinlun values(null,'"+user.get("uname")+"','"+content+"','"+date+"','"+proid+"') ";
System.out.println(sql);
dao.commOper(sql);
request.setAttribute("suc", "");
go("/xiang.jsp?id="+proid, request, response);
}
if(ac.equals("fbhd"))
{
String title = request.getParameter("title");
String filename = request.getParameter("filename");
String content = request.getParameter("content");
String sql = "insert into mixinfo values('"+title+"','"+filename+"','"+content+"','"+date+"') ";
dao.commOper(sql);
request.setAttribute("suc", "");
for (String vstr : values) {
if (vstr == null) vstr = "";
if (vstr.equals("null")) vstr = "";
if (vstr.trim().equals("")) continue;
if (request.getParameter(vstr) != null && !"".equals(request.getParameter(vstr)) && request.getParameter("dk-" + str + "-value") != null) {
String dkv = request.getParameter(vstr);
String dknamevalue = request.getParameter("dk-" + str + "-value");
vstr += " - " + dknamevalue + ":" + dkv;
}
value += vstr + " ~ ";
}
if (value == null) value = "";
if (value.equals("null")) value = "";
if (value.length() > 0) value = value.substring(0, value.length() - 3);
if (typemap.get(str + "---").equals("int")) {
sql += (value.equals("") ? -10 : value) + ",";
} else {
sql += "'" + (value.equals("null") ? "" : value) + "',";
}
} else {
if (typemap.get(str + "---").equals("int")) {
sql += (extmap.get(str) == null ? "" : extmap.get(str)) + ",";
} else {
sql += "'" + (extmap.get(str) == null ? "" : extmap.get(str)) + "',";
}
}
}
sql = sql.substring(0, sql.length() - 1) + ")";
System.out.println(sql);
this.commOper(sql);
st.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
/**
*
* @param 下一页的分页链接
* @param 一页最大记录数
* @param 当前HttpServletRequest对象
* @param 数据库操作对象
*/
public static PageManager getPage(String path, int pageSize,
HttpServletRequest request) {
return new PageManager(path, pageSize, request);
}
/**
*
*
* @param hql语句
*
*/
public void doList(String hql) {
this.count = this.dao.select(hql).size();
if (this.count != 0) {
this.pageNumber = count % this.pageSize == 0 ? this.count
/ this.pageSize : this.count / this.pageSize + 1;
if (this.currentPage > this.pageNumber)
this.currentPage = (int) this.pageNumber;
}
this.request.getSession().setAttribute("currentPage",
String.valueOf(this.currentPage));
this.collection = this.dao.select(hql,
this.currentPage , this.pageSize);
this.refreshUrl();
}
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = Info.generalFileName(fullFile.getName());
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
fileItem.write(newFile);
} catch (Exception e) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploadimg4.jsp?filename="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploadimg5"))
{
try {
String filename="";
request.setCharacterEncoding("utf-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = Info.generalFileName(fullFile.getName());
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
public class TestUpload extends HttpServlet {
/**
* Constructor of the object.
*/
public TestUpload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
if(ac.equals("uploaddoc2"))
{
try {
String filename="";
request.setCharacterEncoding("utf-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = fullFile.getName();
filename = filename.substring(0,filename.lastIndexOf("."))+"-"+Info.getDateStr().replaceAll("-","").replaceAll(" ","").replaceAll(":","")+filename.substring(filename.lastIndexOf("."));
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
fileItem.write(newFile);
} catch (Exception e) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploaddoc2.jsp?docname="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploaddoc3"))
{
try {
String filename="";
request.setCharacterEncoding("utf-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){