Haoyu Chen 5 years ago
commit 5620a9e43d

@ -0,0 +1,60 @@
package BookOperation;
import Connect.Connect;
import JaveBean.Book;
import org.hibernate.Session;
import org.hibernate.Transaction;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class UploadServlet extends HttpServlet {
private Connect con = Connect.getCon();
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=utf-8");
String bookname=request.getParameter("bookname");
String category=request.getParameter("category");
double price= Double.parseDouble(request.getParameter("price"));
System.out.println(bookname);
System.out.println(category);
System.out.println(price);
Session hSession=Connect.getConfig();
Transaction tx=hSession.beginTransaction();
//String hql = "FROM User WHERE username=:name";
//Query query = hSession.createQuery(hql);
//query.setParameter("name",name);
//List results = query.list();
shangchuan(bookname,hSession,category,price);
tx.commit();
// User user= (User) results.get(0);
System.out.println("上传成功");
}
public void shangchuan(String bookname, Session session, String category, double price){
Book book = new Book();
//book.setBookid(7);
book.setBookname(bookname);
book.setPrice(price);
book.setCategory(category);
book.setImageurl("cbsdaka");
book.setSellerId(1);
session.save(book);//保存对象进入数据库
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -4,15 +4,51 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name></display-name>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>Register.RegisterServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>Register.LoginServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>test.UploadServlet</servlet-class>
<servlet-class>BookOperation.UploadServlet</servlet-class>
</servlet>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>ShopCartServlet</servlet-name>
<servlet-class>ShopCar.ShopCartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/Upload.action</url-pattern>
<url-pattern>/upload.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ShopCartServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ShopCartServlet</servlet-name>
<url-pattern>/ShopCartServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>huiyuan.html</welcome-file>
</welcome-file-list>
</web-app>
Loading…
Cancel
Save