Advanced Java Practical Solutions
Advanced Java Practical Solutions
1. JSP + JSTL + EL + Custom Tag
------------------------------
[Link]:
<%@ taglib uri="[Link] prefix="c" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<c:forEach var="p" items="${products}">
Name: ${[Link]}
Price: <t:formatPrice value="${[Link]}" />
</c:forEach>
[Link]:
<%@ attribute name="value" type="[Link]" %>
■ ${value}
Servlet:
List<Product> list = [Link]();
[Link]("products", list);
[Link]("[Link]").forward(request, response);
2. File Upload Servlet
----------------------
[Link]:
<form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file">
</form>
Servlet:
@WebServlet("/upload")
@MultipartConfig
public class UploadServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
Part part = [Link]("file");
String fileName = [Link]();
[Link]("D:/uploads/" + fileName);
}
}
... (Content truncated for brevity in this sample)