package com.hnu.javaee;
import com.hnu.javaee.entity.Order;
import com.hnu.javaee.entity.OrderMgr;
import java.io.IOException;
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 javax.servlet.http.HttpSession;
@WebServlet(name = "OrderServlet",value = "/OrderServlet")
public class OrderServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
HttpSession session = req.getSession();
// 传递参数
req.setCharacterEncoding("UTF-8");
String address = req.getParameter("province")+"省,"+req.getParameter("city")+"市";
String street = req.getParameter("street");
String postCode = req.getParameter("postCode");
String recipient = req.getParameter("recipient");
String invoice = req.getParameter("invoice");
String product = req.getParameter("product");
Order order = new Order(address,street,postCode,recipient,invoice,product);
// 请求转发到orderList.jsp
OrderMgr.add(order);
resp.sendRedirect("orderList.jsp");
}
}
package com.hnu.javaee.entity;
public class Order {
private String address;
private String street;
private String postcode;
private String recipient;
private String invoice;
private String product;
public Order() {
}
public Order(String address, String street, String postcode, String recipient, String invoice,
String product) {
this.address = address;
this.street = street;
this.postcode = postcode;
this.recipient = recipient;
this.invoice = invoice;
this.product = product;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public String getInvoice() {
return invoice;
}
public void setInvoice(String invoice) {
this.invoice = invoice;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
}
package com.hnu.javaee.entity;
import java.util.ArrayList;
public class OrderMgr {
private static ArrayList<Order> orderList = new ArrayList<>();
public ArrayList<Order> getOrderList() {
return orderList;
}
public static void add(Order order) {
orderList.add(order);
}
}
标签:,String,req,street,invoice,recipient,public From: https://www.cnblogs.com/squy/p/16879546.html