This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'anh-fix-admin' of https://github.com/bakaqc/flower into…
… anh-fix-admin
- Loading branch information
Showing
54 changed files
with
1,615 additions
and
775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/bakaqc/flower/controller/AddToCartController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.bakaqc.flower.controller; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
|
||
@WebServlet(name = "AddToCartController", urlPatterns = {"/addcart"}) | ||
public class AddToCartController extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
int pid = Integer.parseInt(request.getParameter("id")); | ||
int amount = Integer.parseInt(request.getParameter("amount")); | ||
|
||
addItem(request, pid, amount); | ||
|
||
response.sendRedirect("cart"); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
} | ||
|
||
public void addItem(HttpServletRequest request, int pid, int amount) { | ||
HttpSession session = request.getSession(); | ||
Map<Integer, Integer> cart = (Map<Integer, Integer>) session.getAttribute("cart"); | ||
|
||
if (cart == null) { | ||
return; | ||
} | ||
|
||
if (cart.containsKey(pid)) { | ||
cart.put(pid, cart.get(pid) + amount); | ||
} else { | ||
cart.put(pid, amount); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.