Created
November 28, 2011 14:29
-
-
Save lukaspili/1400588 to your computer and use it in GitHub Desktop.
Supinfo Clermont Ferrand SupCommerce
This file contains hidden or 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
<%@ page language="java" contentType="text/html; charset=UTF-8" | |
pageEncoding="UTF-8"%> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>SupCommerce - Ajouter un produit</title> | |
</head> | |
<body> | |
<%@ include file="/template/header.jsp" %> | |
<h1>Ajouter un produit</h1> | |
<% if(request.getAttribute("isErrors") != null) { %> | |
<p style="color:red">Des erreurs sont présentes sur le formulaire !</p> | |
<% } %> | |
<form action="<%= application.getContextPath() %>/auth/addProduct" method="POST"> | |
<p> | |
<label for="name">Nom : </label> | |
<input type="text" id="name" name="name" /> | |
</p> | |
<p> | |
<label for="content">Contenu : </label> <br /> | |
<textarea id="content" name="content"></textarea> | |
</p> | |
<p> | |
<label for="price">Prix : </label> | |
<input type="text" id="price" name="price" /> | |
</p> | |
<p> | |
<input type="submit" value="Add" /> | |
</p> | |
</form> | |
<%@ include file="/template/footer.jsp" %> | |
</body> | |
</html> |
This file contains hidden or 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
package com.supinfo.supcommerce.filter; | |
import java.io.IOException; | |
import javax.servlet.Filter; | |
import javax.servlet.FilterChain; | |
import javax.servlet.FilterConfig; | |
import javax.servlet.ServletException; | |
import javax.servlet.ServletRequest; | |
import javax.servlet.ServletResponse; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import javax.servlet.http.HttpSession; | |
public class AuthenticateFilter implements Filter { | |
@Override | |
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, | |
ServletException { | |
HttpServletRequest httpReq = (HttpServletRequest) req; | |
HttpServletResponse httpRep = (HttpServletResponse) resp; | |
HttpSession session = httpReq.getSession(); | |
if(session.getAttribute("login") == null) { | |
httpRep.sendRedirect(req.getServletContext().getContextPath() + "/login.html"); | |
return; | |
} | |
chain.doFilter(req, resp); | |
} | |
@Override | |
public void destroy() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void init(FilterConfig arg0) throws ServletException { | |
// TODO Auto-generated method stub | |
} | |
} |
This file contains hidden or 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
package com.supinfo.supcommerce.servlet; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import com.supinfo.sun.supcommerce.bo.SupProduct; | |
import com.supinfo.sun.supcommerce.doa.SupProductDao; | |
public class InsertSomeProductServlet extends HttpServlet { | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
SupProduct product = new SupProduct(); | |
product.setName("Foo"); | |
product.setContent("Bar"); | |
product.setPrice(10); | |
SupProductDao.addProduct(product); | |
resp.setContentType("text/html"); | |
resp.getWriter().println("Le produit a été ajouté !"); | |
} | |
} |
This file contains hidden or 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
<%@page import="com.supinfo.sun.supcommerce.doa.SupProductDao"%> | |
<%@page import="com.supinfo.sun.supcommerce.bo.SupProduct"%> | |
<%@ page language="java" contentType="text/html; charset=UTF-8" | |
pageEncoding="UTF-8"%> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>SupCommerce - Liste des produits</title> | |
</head> | |
<body> | |
<%@ include file="/template/header.jsp" %> | |
<h2>Liste des produits</h2> | |
<% for(SupProduct product : SupProductDao.getAllProducts()) { %> | |
<p> | |
<strong><%= product.getName() %></strong> <br /> | |
<%= product.getContent() %> <br /> | |
<%= product.getPrice() %> euros <br /> | |
<a href="showProduct.jsp?id=<%= product.getId() %>">Voir en détail</a> | |
</p> | |
<% } %> | |
<%@ include file="/template/footer.jsp" %> | |
</body> | |
</html> |
This file contains hidden or 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
package com.supinfo.supcommerce.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 com.supinfo.sun.supcommerce.bo.SupProduct; | |
import com.supinfo.sun.supcommerce.doa.SupProductDao; | |
public class ListProductServlet extends HttpServlet { | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
showList(req, resp); | |
} | |
@Override | |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
showList(req, resp); | |
} | |
private void showList(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |
resp.setContentType("text/html"); | |
PrintWriter out = resp.getWriter(); | |
out.println("<h1>Liste des produits</h1>"); | |
out.println("<p><a href=\"auth/basicInsert\">Ajouter un nouveau produit</a></p>"); | |
for (SupProduct product : SupProductDao.getAllProducts()) { | |
out.println("<p>"); | |
out.println("Name : <a href=\"showProduct?id=" + product.getId() + "\">" + product.getName() + "</a><br />"); | |
out.println("Content : " + product.getName() + "<br />"); | |
out.println("Price : " + product.getName()); | |
out.println("</p>"); | |
} | |
} | |
} |
This file contains hidden or 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>SupCommerce login</title> | |
</head> | |
<body> | |
<h1>Login</h1> | |
<form action="login" method="post"> | |
<label for="login">Login :</label> <input id="login" type="text" | |
name="login" /> <br /> | |
<label for="password">Password :</label> <input | |
id="password" type="password" name="password" /> <br /> | |
<input type="submit" value="Login" /> | |
</form> | |
</body> | |
</html> |
This file contains hidden or 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
package com.supinfo.supcommerce.servlet; | |
import java.io.IOException; | |
import javax.servlet.RequestDispatcher; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
public class LoginServlet extends HttpServlet { | |
private static final String LOGIN = "foo"; | |
private static final String PASSWORD = "bar"; | |
@Override | |
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
String login = req.getParameter("login"); | |
String password = req.getParameter("password"); | |
if (!LOGIN.equalsIgnoreCase(login) || !PASSWORD.equals(password)) { | |
resp.sendRedirect("login.html"); | |
return; | |
} | |
req.getSession().setAttribute("login", login); | |
resp.sendRedirect(req.getContextPath()); | |
} | |
} |
This file contains hidden or 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
<%@page import="com.supinfo.sun.supcommerce.exception.UnknownProductException"%> | |
<%@page import="com.supinfo.sun.supcommerce.doa.SupProductDao"%> | |
<%@page import="com.supinfo.sun.supcommerce.bo.SupProduct"%> | |
<%@ page language="java" contentType="text/html; charset=UTF-8" | |
pageEncoding="UTF-8"%> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>SupCommerce - Détail d'un produit</title> | |
</head> | |
<body> | |
<% String idParam = request.getParameter("id"); %> | |
<% long id = 0; | |
try { | |
id = Long.valueOf(idParam); | |
} catch (NumberFormatException e) { | |
response.sendRedirect("listProduct.jsp"); | |
return; | |
} %> | |
<% SupProduct product = null; | |
try { | |
product = SupProductDao.findProductById(id); | |
} catch (UnknownProductException e) { | |
response.sendRedirect("listProduct.jsp"); | |
return; | |
} %> | |
<%@ include file="/template/header.jsp" %> | |
<h2><%= product.getName() %></h2> | |
<p> | |
<%= product.getContent() %> <br /> | |
<%= product.getPrice() %> euros <br /> | |
</p> | |
<%@ include file="/template/footer.jsp" %> | |
</body> | |
</html> |
This file contains hidden or 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
package com.supinfo.supcommerce.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 com.supinfo.sun.supcommerce.bo.SupProduct; | |
import com.supinfo.sun.supcommerce.doa.SupProductDao; | |
import com.supinfo.sun.supcommerce.exception.UnknownProductException; | |
public class ShowProductServlet extends HttpServlet { | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
resp.setContentType("text/html"); | |
PrintWriter out = resp.getWriter(); | |
String idParam = req.getParameter("id"); | |
long id; | |
try { | |
id = Long.valueOf(idParam); | |
} catch (NumberFormatException e) { | |
out.println("<p>Id invalide !</p>"); | |
return; | |
} | |
SupProduct product; | |
try { | |
product = SupProductDao.findProductById(id); | |
} catch (UnknownProductException e) { | |
out.println("<p>Le produit n'existe pas !</p>"); | |
return; | |
} | |
out.println("<p>"); | |
out.println("Name : " + product.getName() + "<br />"); | |
out.println("Content : " + product.getName() + "<br />"); | |
out.println("Price : " + product.getName()); | |
out.println("</p>"); | |
out.println("<p><a href=\"listProduct\">Retourner à la liste des produits</a></p>"); | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | |
id="WebApp_ID" version="3.0"> | |
<display-name>SupCommerceClermont</display-name> | |
<welcome-file-list> | |
<welcome-file>index.jsp</welcome-file> | |
</welcome-file-list> | |
<!-- PUBLIC --> | |
<servlet> | |
<servlet-name>ListProductServlet</servlet-name> | |
<servlet-class>com.supinfo.supcommerce.servlet.ListProductServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>ListProductServlet</servlet-name> | |
<url-pattern>/listProduct</url-pattern> | |
</servlet-mapping> | |
<servlet> | |
<servlet-name>ShowProductServlet</servlet-name> | |
<servlet-class>com.supinfo.supcommerce.servlet.ShowProductServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>ShowProductServlet</servlet-name> | |
<url-pattern>/showProduct</url-pattern> | |
</servlet-mapping> | |
<servlet> | |
<servlet-name>LoginServlet</servlet-name> | |
<servlet-class>com.supinfo.supcommerce.servlet.LoginServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>LoginServlet</servlet-name> | |
<url-pattern>/login</url-pattern> | |
</servlet-mapping> | |
<servlet> | |
<servlet-name>LogoutServlet</servlet-name> | |
<servlet-class>com.supinfo.supcommerce.servlet.LogoutServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>LogoutServlet</servlet-name> | |
<url-pattern>/logout</url-pattern> | |
</servlet-mapping> | |
<!-- AUTH AREA --> | |
<servlet> | |
<servlet-name>AddProductServlet</servlet-name> | |
<servlet-class>com.supinfo.supcommerce.servlet.AddProductServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>AddProductServlet</servlet-name> | |
<url-pattern>/auth/addProduct</url-pattern> | |
</servlet-mapping> | |
<servlet> | |
<servlet-name>InsertSomeProductServlet</servlet-name> | |
<servlet-class>com.supinfo.supcommerce.servlet.InsertSomeProductServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>InsertSomeProductServlet</servlet-name> | |
<url-pattern>/auth/basicInsert</url-pattern> | |
</servlet-mapping> | |
<!-- FILTERS --> | |
<filter> | |
<filter-name>AuthenticateFilter</filter-name> | |
<filter-class>com.supinfo.supcommerce.filter.AuthenticateFilter</filter-class> | |
</filter> | |
<filter-mapping> | |
<filter-name>AuthenticateFilter</filter-name> | |
<url-pattern>/auth/*</url-pattern> | |
</filter-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment