实验描述:
     (实验三的任务)用户网上注册,注册信息写入数据库。
     (实验四的任务)用户登陆后,进入网上购物系统,选择书籍,加入购物车,购物完毕进入结账界面(可模拟一下,简单输出一些信息);在用户购物的期间内,可随时查看购物车的状态,进入购物车后,也可返回再选择商品;在购物期间,用户也可以注销。

本次的任务:管理员以“admin”为用户名进行注册(或登录),对书籍进行后台管理(增、删、改
、查)。

问题:

sql=sql+"publisher='"+publisher+"‘ where bookname='"+name+"'";与

sql=sql+"publisher='"+publisher+"'"+" where bookname='"+name+"'";

区别很大,看似很相同,第一个不能运行,第二个oK

感受:

很多语句和一些简单的应用很不熟,犯了很多小白问题

练习太少了,

贴个后台代码:

jsp:页面

Backmanger.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><form action="backLogin.jsp" method="post"><table><tr><td colspan="2" align="center">后台管理登陆</td></tr><tr><td>数据库名称:</td><td><input type="text" name="pdatebasename"/></td></tr><tr><td>表的名字:</td><td><input type="text" name="ptable"/></td></tr> <tr><td>用户名:</td><td><input type="text" name="puser"/></td></tr> <tr><td>密码:</td><td><input type="password" name="pwd"/></td></tr>    <tr><td  ><input type="submit" value=" 管理员登陆"/></td></tr>  </table></form></body>
</html>

logIn.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="dao.backConnect"  %>
<%@ page import="bean.backConnectbean" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'backLogin.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><jsp:useBean id="user1" class="bean.backConnectbean" scope="session"></jsp:useBean><jsp:setProperty property="*" name="user1"/><%//     System.out.println(user.getPdatebasename()+"  "+user.getPuser()+" "+user.getPwd());// String ps=request.getParameter("pwd");boolean flag=(new backConnect()).getConn(user1.getPdatebasename(),user1.getPuser(),user1.getPwd());System.out.println("flag  初始化成功");if(flag){response.sendRedirect("displayBook1.jsp");}else{response.sendRedirect("BackManger.jsp");}%></body>
</html>

display

   <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="dao.BookDao"%>
<%@page import="bean.BookBean"%>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'displayBooks.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><%%>欢迎您 管理员,请选择相关操作<form action="process.jsp" method="post">"<table border="1"><tr><td>请选择</td><td>书名</td><td>出版社</td><td>作者</td><td>价格</td><td>出版日期</td><td>库存数量</td></tr><%BookDao bookDao=new BookDao();ArrayList list=bookDao.selectAllBooks();Iterator it=list.iterator();while(it.hasNext()){BookBean book=(BookBean)it.next();%><tr><td><input type="checkbox"  name="bookid" value="<%=book.getBookid() %>"/> </td><td><%=book.getBookname() %></td><td><%=book.getPublisher() %></td><td><%=book.getAuthor() %></td><td><%=book.getPrice() %></td><td><%=book.getPublishDate() %></td><td><%=book.getCount() %></td></tr><%   }%><tr><td><select name="flag">
<option value="增加" selected>增加</option>
<option value="减少">减少</option>
<option value="改正">改正</option>
<option value="查询">查询</option>
</select><br></inut></td></tr><tr><td colspan="7" align="center"><input type="submit" value="提交"/></td></tr></table></form></body>
</html>

process.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'process.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><%String flag=request.getParameter("flag");if(flag.equals("增加")){response.sendRedirect("zhengjia.jsp");}else if(flag.equals("减少")){response.sendRedirect("jianshao.jsp");}else if(flag.equals("改正")){response.sendRedirect("gaizheng.jsp");}else  if(flag.equals("查询")){response.sendRedirect("chaxun.jsp");}%></body>
</html>

zhengjia.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'regist.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><form action="zhengjiaservlet" method="get"><table><tr><td colspan="2" align="center">要增加的内容</td></tr><tr><td>编号:</td><td><input type="text" name="bookid"/></td></tr><tr><td>书名:</td><td><input type="text" name="bookname"/></td></tr><tr><td>出版社:</td><td><input type="text" name="publisher"/></td></tr>  <tr><td>作者:</td><td><input type="text" name="author" /> <tr><td>价格:</td><td><input type="text" name="price"/></td></tr>   <tr><td>出版日期:</td><td><input type="text" name="publishDate"/></td></tr><tr><td>数量:</td><td><input type="text" name="count"/></td></tr>   <tr><td colspan="2" align="center"><input type="submit" value="提交"/></td></tr>   </table></form></body>
</html>

jianshao.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'regist.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><form action="jianshaoservlet" method="get"><table><tr><td colspan="2" align="center">要删去的书名</td></tr><tr><td>书名:</td><td><input type="text" name="bookname"/></td></tr><tr><td colspan="2" align="center"><input type="submit" value="提交"/></td></tr>   </table></form></body>
</html>

gaizheng.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'regist.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><form action="gaizheng" method="get"><table><tr><td colspan="2" align="center">要改正的书名及要修改的相关信息</td></tr><tr><td>书名:</td><td><input type="text" name="bookname"/></td></tr><tr><td>出版社:</td><td><input type="text" name="publisher"/></td></tr>   <tr><td>作者:</td><td><input type="text" name="author" /> <tr><td>价格:</td><td><input type="text" name="price"/></td></tr>   <tr><td>出版日期:</td><td><input type="text" name="publishDate"/></td></tr><tr><td>数量:</td><td><input type="text" name="count"/></td></tr>   <tr><td colspan="2" align="center"><input type="submit" value="提交"/></td></tr>   </table></form></body>
</html>

chaxun.jsp (水水滴)

   <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="dao.BookDao"%>
<%@page import="bean.BookBean"%>
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="<%=basePath%>"><title>My JSP 'displayBooks.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><%request.setCharacterEncoding("utf-8");response.setCharacterEncoding("utf-8"); %><%%><p>书籍信息</p><form action="process.jsp" method="post">"<table border="1"><tr><td>编号</td><td>书名</td><td>出版社</td><td>作者</td><td>价格</td><td>出版日期</td><td>库存数量</td></tr><%BookDao bookDao=new BookDao();ArrayList list=bookDao.selectAllBooks();Iterator it=list.iterator();while(it.hasNext()){BookBean book=(BookBean)it.next();%><tr><td><input type="checkbox"  name="bookid" value="<%=book.getBookid() %>"/> </td><td><%=book.getBookname() %></td><td><%=book.getPublisher() %></td><td><%=book.getAuthor() %></td><td><%=book.getPrice() %></td><td><%=book.getPublishDate() %></td><td><%=book.getCount() %></td></tr><%   }%><tr><td></inut></td></tr></td></tr></table></form></body>
</html>

bean

backbean.

package dao;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;public class backConnect {public boolean getConn(String datebaseName,String user,String pwd){try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");System.out.print(datebaseName+"  "+user+"  "+pwd);String url="jdbc:sqlserver://127.0.0.1:1433;databaseName="+datebaseName;Connection con;con=DriverManager.getConnection(url,user,pwd);System.out.print("连接成功");return true;} catch (SQLException e) {// TODO Auto-generated catch blockSystem.out.print("连接失败一");e.printStackTrace();} catch (ClassNotFoundException e) {// TODO Auto-generated catch blockSystem.out.print("连接失败二");e.printStackTrace();}return false;}
}

dao 里的

backconnect.java

package bean;public class backConnectbean {private String pdatebasename="nothing";private String ptable="nothing";private String puser="nothing";private String pwd="nothing";public String getPdatebasename() {return pdatebasename;}public void setPdatebasename(String datebaseName) {this.pdatebasename = datebaseName;}public String getPtable() {return ptable;}public void setPtable(String ptable) {this.ptable = ptable;}public String getPuser() {return puser;}public void setPuser(String puser) {this.puser = puser;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}}

巨关键的bookdao.java

package dao;import dao.BaseDao;
import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import bean.BookBean;
import java.sql.*;
public class BookDao {Connection con=new BaseDao().getConn();private PreparedStatement pstat;String sql="";public boolean Zhengjia(BookBean user){sql = "insert into book values(?,?,?,?,?,?,?)";try{pstat = con.prepareStatement(sql);pstat.setString(1,user.getBookid());pstat.setString(2,user.getBookname());pstat.setString(3,user.getPublisher());pstat.setString(4,user.getAuthor());pstat.setString(5,user.getPrice());pstat.setString(6,user.getPublishDate());pstat.setInt(7,user.getCount());pstat.executeUpdate();pstat.close();con.close();return true;}catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return false;}public boolean jianshao(String name){sql = "delete from  book where bookname='"+name+"'";try{Statement sql1;sql1=con.createStatement();sql1.executeUpdate(sql);con.close();return true;}catch (SQLException e) {// TODO Auto-generated catch block//e.printStackTrace();}return false;}public boolean gaizheng(String name,String publisher,String author,String price,String publishDate,int count){if(true){System.out.println(name+publisher+author+price+publishDate+count);}String  sql = "update  book set ";String  sql1 = "update  book set ";String  sql2 = "update  book set ";String  sql3 = "update  book set ";String  sql4 = "update  book set ";if(publisher!=null){sql=sql+"publisher='"+publisher+"'"+" where bookname='"+name+"'";}if(author!=null){sql1+="author='"+author+"'"+" where bookname='"+name+"'";}if(price!=null){sql2+="price='"+price+"'"+" where bookname='"+name+"'";}if(publishDate!=null){sql3+="poublishDate='"+publishDate+"'"+" where bookname='"+name+"'";}if(count!=0 ){sql4+="count='"+count+"'"+" where bookname='"+name+"'";;}System.out.println(sql);System.out.println("try 前");try{Statement sql11;sql11=con.createStatement();sql11.executeUpdate(sql);System.out.println("try 中");sql11.executeUpdate(sql1);sql11.executeUpdate(sql2);sql11.executeUpdate(sql3);sql11.executeUpdate(sql4);con.close();System.out.println("try 后");return true;}catch (SQLException e) {// TODO Auto-generated catch block//e.printStackTrace();}return false;}public ArrayList selectAllBooks(){ArrayList<BookBean> list=new ArrayList();String selectSql="select * from book";try {PreparedStatement pst=con.prepareStatement(selectSql);ResultSet rs=pst.executeQuery();while(rs.next()){BookBean book=new BookBean();book.setBookid(rs.getString(1));book.setBookname(rs.getString(2));book.setPublisher(rs.getString(3));book.setAuthor(rs.getString(4));book.setPrice(rs.getString(5));book.setPublishDate(rs.getString(6));book.setCount(rs.getInt(7));list.add(book);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return list;}public String selectBookById(String bookId){String bookName=null;String selectSql="select bookname from book where bookid=?";try {PreparedStatement pst=con.prepareStatement(selectSql);pst.setString(1, bookId);ResultSet rs=pst.executeQuery();if(rs.next()){bookName=rs.getString(1);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return bookName;}
}

servlet

zhengjia.jsp

package servlet;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import dao.BookDao;public class gaizheng extends HttpServlet {/*** Constructor of the object.*/public gaizheng() {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 {response.setContentType("text/html");response.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");String bookname = new String(request.getParameter("bookname").getBytes("ISO8859_1"),"utf-8");String publisher = new String(request.getParameter("publisher").getBytes("ISO8859_1"),"utf-8");String author = new String(request.getParameter("author").getBytes("ISO8859_1"),"utf-8");String price = new String(request.getParameter("price").getBytes("ISO8859_1"),"utf-8");String publishDate = new String(request.getParameter("publishDate").getBytes("ISO8859_1"),"utf-8");String count1 = new String(request.getParameter("count").getBytes("ISO8859_1"),"utf-8");int count=Integer.parseInt(count1);BookDao dao = new BookDao();if(dao.gaizheng(bookname,publisher,author,price,publishDate,count)){response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print(" Successful!!! ");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}else{response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print(" Defeated!!! ");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}}/*** 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 {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print("    This is ");out.print(this.getClass());out.println(", using the POST method");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}/*** Initialization of the servlet. <br>** @throws ServletException if an error occurs*/public void init() throws ServletException {// Put your code here}}

jianshao.jsp

package servlet;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import dao.BookDao;public class jianshaoservlet extends HttpServlet {/*** Constructor of the object.*/public jianshaoservlet() {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 {response.setContentType("text/html");response.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");String bookname = new String(request.getParameter("bookname").getBytes("ISO8859_1"),"utf-8");BookDao dao = new BookDao();if(dao.jianshao(bookname)){response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print(" Successful!!! ");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}else{response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print(" Defeated!!! ");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}}/*** 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 {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print("    This is ");out.print(this.getClass());out.println(", using the POST method");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}/*** Initialization of the servlet. <br>** @throws ServletException if an error occurs*/public void init() throws ServletException {// Put your code here}}

gaizheng.jsp

package servlet;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import dao.BookDao;public class gaizheng extends HttpServlet {/*** Constructor of the object.*/public gaizheng() {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 {response.setContentType("text/html");response.setCharacterEncoding("utf-8");request.setCharacterEncoding("utf-8");String bookname = new String(request.getParameter("bookname").getBytes("ISO8859_1"),"utf-8");String publisher = new String(request.getParameter("publisher").getBytes("ISO8859_1"),"utf-8");String author = new String(request.getParameter("author").getBytes("ISO8859_1"),"utf-8");String price = new String(request.getParameter("price").getBytes("ISO8859_1"),"utf-8");String publishDate = new String(request.getParameter("publishDate").getBytes("ISO8859_1"),"utf-8");String count1 = new String(request.getParameter("count").getBytes("ISO8859_1"),"utf-8");int count=Integer.parseInt(count1);BookDao dao = new BookDao();if(dao.gaizheng(bookname,publisher,author,price,publishDate,count)){response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print(" Successful!!! ");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}else{response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print(" Defeated!!! ");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}}/*** 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 {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("  <BODY>");out.print("    This is ");out.print(this.getClass());out.println(", using the POST method");out.println("  </BODY>");out.println("</HTML>");out.flush();out.close();}/*** Initialization of the servlet. <br>** @throws ServletException if an error occurs*/public void init() throws ServletException {// Put your code here}}

代码打包:

去我的资源里下吧

这个链接是城通网盘 的链接

http://home.400gb.com/mydisk.php?item=files&action=index&folder_id=1213171

实现网上购物系统的后台管理(增、删、改、查图书)。相关推荐

  1. python学生姓名添加删除_python-函数-实现学生管理系统,完成对学员的增,删,改,查和退出学生管理系统。...

    实现学生管理系统,完成对学员的增,删,改,查和退出学生管理系统. 要求1:使用一个list用于保存学生的姓名. 要求2:输入0显示所有学员信息,1代表增加,2代表删除,3代表修改,4代表查询,exit ...

  2. 表单的增 删 改 查

    django单表操作 增 删 改 查 一.实现:增.删.改.查 1.获取所有数据显示在页面上 model.Classes.object.all(),拿到数据后,渲染给前端;前端通过for循环的方式,取 ...

  3. properties(map)增.删.改.查.遍历

    import java.util.Map; import java.util.Properties; import java.util.Set;/*** properties(map)增.删.改.查. ...

  4. PySpark︱DataFrame操作指南:增/删/改/查/合并/统计与数据处理

    笔者最近需要使用pyspark进行数据整理,于是乎给自己整理一份使用指南.pyspark.dataframe跟pandas的差别还是挺大的. 文章目录 1.-------- 查 -------- -- ...

  5. pyRedis - 操作指南:增/删/改/查、管道与发布订阅功能

    文章目录 1 redis docker 部署与安装 2 py - redis的使用 2.1 redis的连接 2.2 常规属性查看 2.2.2 关于删除 2.3 STRING 字符串的操作 2.4 H ...

  6. Go 学习笔记(50)— Go 标准库之 net/url(查询转义、查询参数增/删/改/查、解析URL)

    1. URL 概述 import "net/url" url 包解析 URL 并实现了查询的转码.URL 提供了一种定位因特网上任意资源的手段,但这些资源是可以通过各种不同的方案( ...

  7. Python 操作 Elasticsearch 实现 增 删 改 查

    Github 地址:https://github.com/elastic/elasticsearch-py/blob/master/docs/index.rst 官网地址:https://elasti ...

  8. list 增 删 改 查 及 公共方法

    1 # 热身题目:增加名字,并且按q(不论大小写)退出程序 2 li = ['taibai','alex','wusir','egon','女神'] 3 while 1: 4 username = i ...

  9. Linux技术--mysql数据库增-删-改-查

    # mysql 数据库 ## 数据库的操作 ### 五个单位 * 数据库服务器   Linux或者 windows  * 数据库  * 数据表 * 数据字段 * 数据行 ### 连接数据库 ``` 1 ...

最新文章

  1. bigdecimal正确用法_深入理解 BigDecimal 的使用
  2. Verilog中的二维数组及其初始化
  3. Android之SharedPreferences 存储复杂对象
  4. 【Objective-C】Http常用API、同步请求与异步请求[转]
  5. 使用SignalR和SQLTableDependency进行记录更改的SQL Server通知
  6. 吴恩达机器学习练习2:Regularized logistic regression
  7. 工商服务代理行业解决方案
  8. python 单引号,双引号用法的理解
  9. 计算机 保护眼睛 颜色,教你把电脑屏幕设置成可以保护眼睛的颜色
  10. 量化C++国产框架千星+ WonderTrader
  11. Chrome设置--disable-web-security解决跨域问题
  12. HTML中添加超链接、音频标签、视频标签、内嵌框架标签
  13. 千纸鹤(小纸片)全套源码
  14. 分享一个ZPL指令在线测试网址
  15. C语言自学路之计算平方(输入验证)
  16. 产品思维的修炼–技术的必修课
  17. 动画原理与网络游戏设计——课程学习笔记1~3周
  18. 计算机网络知识之URL、IP、子网掩码、端口号
  19. 银行联行号-联行号api接口-联行号数据源
  20. 琅琊领航联盟|TK联盟首期私享会圆满结束

热门文章

  1. 华视身份证阅读器SDK使用手册
  2. vue引入html报错
  3. 亚马逊平台的优势有哪些?
  4. 职场潜规则之——言及莫论领导是非
  5. pr基本图形模板无法使用_辣么美的PR基本图形模板,不能改字体怎么办
  6. 《夏风》刊发的几组诗词
  7. 【NOIP普及组】 1945:【09NOIP普及组】多项式输出
  8. PT100三线制恒流源接法
  9. Matlab学习——曲柄滑块的运动仿真
  10. 程序 卡塔_我想念微软恩卡塔