Các bạn tham khảo nhe
Buổi Lab 06 JSTL
Nội dung hướng dẫn sử dụng thư viện JSTL để truy vấn dữ liệu
Buổi 07: Internationalization
Các bạn download ở đây
Buổi 10: Create Dynamic custom tag and tag file in JSP
JSP Internationalization – Video hướng dẫn tạo trang web đa ngôn ngữc cơ bản bằng JSP
JSP Aptech All demo – Bài tập tổng hợp JSP i10
STL – set:datasource, sql:query, sql:update, sql:param, sql:transaction
Bài tập xây dựng một ứng dụng bán điện thoại đơn giản bằng jsp
Tạo và sử dụng Custom Tag trong JSP thông qua Tag interface
--------------------------------
Hi vọng có ích cho các bạn
Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts
Friday, March 1, 2013
Wednesday, December 26, 2012
Hướng dẫn tạo trang giỏ hàng đơn giản với jsp
Chúng ta cùng nhau xây dựng chức năng giỏ hàng một cách đơn giản nhất trong jsp như sau:
[caption id="attachment_859" align="alignnone" width="300"]
Trang chọn sản phẩm[/caption]
Sau khi chọn sản phẩm sẽ chuyển sang trang giỏ hàng
[caption id="attachment_860" align="alignnone" width="300"]
Giỏ hàng[/caption]
Các bạn có thể tham khảo bên dưới
Trang sản phẩm
[sourcecode language="html"]
<%--
Document : index
Created on : Dec 25, 2012, 3:08:22 PM
Author : Ngo Tuong Dan
--%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
h1
{
color: yellowgreen;
font-style: italic;
}
div
{
margin-left: auto;
margin-right: auto;
width: 300px;
}
input[type=text]
{
width:150px;
text-align:left;
border:thin solid gray;
padding: 2px 5px 2px 5px;
border-radius: 3px 3px 3px 3px;
}
input[type=submit]
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 3px 5px 3px 5px;
border-radius: 3px 3px 3px 3px;
background-color: orange;
}
input[type=submit]:hover
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 3px 5px 3px 5px;
border-radius: 3px 3px 3px 3px;
background-color: yellowgreen;
}
</style>
<title>JSP Page</title>
</head>
<body>
<div>
<h1>Shopping card demo</h1>
<%
if (request.getParameter("btnOK") != null) {
codes.item item = new codes.item();
item.setId(Integer.parseInt(request.getParameter("txtID")));
item.setPrice(Integer.parseInt(request.getParameter("txtPrice")));
item.setQuantity(Integer.parseInt(request.getParameter("txtQuantity")));
java.util.ArrayList orders = new ArrayList();
if (session.getAttribute("Orders") != null) {
orders = ((java.util.ArrayList) session.getAttribute("Orders"));
}
orders.add(item);
session.setAttribute("Orders", orders);
response.sendRedirect("list.jsp");
}
%>
<form method="post">
<table>
<tr>
<td>
ID</td>
<td>
<input type="text" name="txtID" />
</td>
</tr>
<tr>
<td>
Price
</td>
<td>
<input type="text" name="txtPrice"/>
</td>
</tr>
<tr>
<td>
Quantity
</td>
<td>
<input type="text" name="txtQuantity"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit"value="OK" name="btnOK"/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
[/sourcecode]
Trang giỏ hàng
[sourcecode language="html"]
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
h1
{
color: yellowgreen;
font-style: italic;
}
div
{
margin-left: auto;
margin-right: auto;
width: 300px;
}
table
{
border: 1px solid gray;
padding: 3px 3px 3px 3px;
}
th
{
color: brown;
}
.back
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 2px 5px 2px 5px;
border-radius: 3px 3px 3px 3px;
background-color: orange;
}
.back:hover
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 3px 5px 3px 5px;
border-radius: 3px 3px 3px 3px;
background-color: yellowgreen;
}
</style>
</head>
<body>
<div>
<h1>Your card</h1>
<table>
<tr>
<th>ID</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Operator</th>
</tr>
<%
java.util.ArrayList orders = new ArrayList();
codes.item item = new codes.item();
if (session.getAttribute("Orders") != null) {
orders = ((java.util.ArrayList) session.getAttribute("Orders"));
}
int count = orders.size() - 1;
while (count > 0) {
item = (codes.item) orders.get(count);
if (request.getParameter("id") != null) {
if (item.getId() == Integer.parseInt(request.getParameter("id"))) {
orders.remove(item);
count--;
continue;
}
}
out.print("<tr>");
out.print("<td>" + item.getId() + "</td>");
out.print("<td>" + item.getPrice() + "</td>");
out.print("<td>" + item.getQuantity() + "</td>");
out.print("<td>" + item.getQuantity() * item.getPrice() + "</td>");
out.print("<td> <a href='?id=" + item.getId() + "'>Delete</a></td>");
count--;
out.print("</tr>");
}
%>
</table>
<br/>
<a class="back" href="index.jsp">continue</a>
</div>
</body>
</html>
[/sourcecode]
[caption id="attachment_859" align="alignnone" width="300"]
Sau khi chọn sản phẩm sẽ chuyển sang trang giỏ hàng
[caption id="attachment_860" align="alignnone" width="300"]
Các bạn có thể tham khảo bên dưới
Trang sản phẩm
[sourcecode language="html"]
<%--
Document : index
Created on : Dec 25, 2012, 3:08:22 PM
Author : Ngo Tuong Dan
--%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
h1
{
color: yellowgreen;
font-style: italic;
}
div
{
margin-left: auto;
margin-right: auto;
width: 300px;
}
input[type=text]
{
width:150px;
text-align:left;
border:thin solid gray;
padding: 2px 5px 2px 5px;
border-radius: 3px 3px 3px 3px;
}
input[type=submit]
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 3px 5px 3px 5px;
border-radius: 3px 3px 3px 3px;
background-color: orange;
}
input[type=submit]:hover
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 3px 5px 3px 5px;
border-radius: 3px 3px 3px 3px;
background-color: yellowgreen;
}
</style>
<title>JSP Page</title>
</head>
<body>
<div>
<h1>Shopping card demo</h1>
<%
if (request.getParameter("btnOK") != null) {
codes.item item = new codes.item();
item.setId(Integer.parseInt(request.getParameter("txtID")));
item.setPrice(Integer.parseInt(request.getParameter("txtPrice")));
item.setQuantity(Integer.parseInt(request.getParameter("txtQuantity")));
java.util.ArrayList orders = new ArrayList();
if (session.getAttribute("Orders") != null) {
orders = ((java.util.ArrayList) session.getAttribute("Orders"));
}
orders.add(item);
session.setAttribute("Orders", orders);
response.sendRedirect("list.jsp");
}
%>
<form method="post">
<table>
<tr>
<td>
ID</td>
<td>
<input type="text" name="txtID" />
</td>
</tr>
<tr>
<td>
Price
</td>
<td>
<input type="text" name="txtPrice"/>
</td>
</tr>
<tr>
<td>
Quantity
</td>
<td>
<input type="text" name="txtQuantity"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit"value="OK" name="btnOK"/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
[/sourcecode]
Trang giỏ hàng
[sourcecode language="html"]
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
h1
{
color: yellowgreen;
font-style: italic;
}
div
{
margin-left: auto;
margin-right: auto;
width: 300px;
}
table
{
border: 1px solid gray;
padding: 3px 3px 3px 3px;
}
th
{
color: brown;
}
.back
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 2px 5px 2px 5px;
border-radius: 3px 3px 3px 3px;
background-color: orange;
}
.back:hover
{
width:75px;
text-align:center;
border:thin solid gray;
padding: 3px 5px 3px 5px;
border-radius: 3px 3px 3px 3px;
background-color: yellowgreen;
}
</style>
</head>
<body>
<div>
<h1>Your card</h1>
<table>
<tr>
<th>ID</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Operator</th>
</tr>
<%
java.util.ArrayList orders = new ArrayList();
codes.item item = new codes.item();
if (session.getAttribute("Orders") != null) {
orders = ((java.util.ArrayList) session.getAttribute("Orders"));
}
int count = orders.size() - 1;
while (count > 0) {
item = (codes.item) orders.get(count);
if (request.getParameter("id") != null) {
if (item.getId() == Integer.parseInt(request.getParameter("id"))) {
orders.remove(item);
count--;
continue;
}
}
out.print("<tr>");
out.print("<td>" + item.getId() + "</td>");
out.print("<td>" + item.getPrice() + "</td>");
out.print("<td>" + item.getQuantity() + "</td>");
out.print("<td>" + item.getQuantity() * item.getPrice() + "</td>");
out.print("<td> <a href='?id=" + item.getId() + "'>Delete</a></td>");
count--;
out.print("</tr>");
}
%>
</table>
<br/>
<a class="back" href="index.jsp">continue</a>
</div>
</body>
</html>
[/sourcecode]
Sunday, April 1, 2012
Simple JSP - Tao trang sp đơn giản
1.Using include
- Create page
[sourcecode language="html" wraplines="false"]
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page</h1>
<%@ include file="Input.jsp"%>
</body>
</html>
[/sourcecode]
With Input .jsp will create in next exercise.
2. Using resource in jsp page
- Create Input.jsp
[sourcecode language="html" wraplines="false"]
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String fNumber = request.getParameter("fNumber");
String sNumber = request.getParameter("sNumber");
String oper = request.getParameter("oper");
String result="";
if(oper!=null) {
if(oper.equalsIgnoreCase("+"))
result=(Integer.parseInt(fNumber) + Integer.parseInt(sNumber))+"";
else if(oper.equalsIgnoreCase("-"))
result=(Integer.parseInt(fNumber) - Integer.parseInt(sNumber))+"";
else if(oper.equalsIgnoreCase("*"))
result=(Integer.parseInt(fNumber) * Integer.parseInt(sNumber))+"";
else if(oper.equalsIgnoreCase("/"))
result=(Integer.parseInt(fNumber) / Integer.parseInt(sNumber))+"";
else
result="NaN";
}
%>
<h1>This is demo simple JSP</h1>
<form action="Input.jsp" method="post">
<br>
<table width="400px" border="1px" cellpadding="0">
<tr>
<td>
First number:
</td>
<td>
<input type="text" name="fNumber" value="<%=fNumber%>"/>
</td>
</tr>
<tr>
<td>
Second number:
</td>
<td>
<input type="text" name="sNumber" value="<%=sNumber%>"/><br>
</td>
</tr>
<tr>
<td>
Operator:
</td>
<td>
<input type="text" name="oper" value="<%=oper%>"/><br>
</td>
</tr>
<tr>
<td>
Result
</td>
<td>
<input type="text" name="Result" value="<%=result%>">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="Submit" value=Submit>
</td>
</tr>
</table>
</form>
</body>
</html>
[/sourcecode]
Tuesday, November 15, 2011
Subscribe to:
Posts (Atom)