Java web:轉(zhuǎn)發(fā)方式跳轉(zhuǎn),頁(yè)面上顯示,友情鏈接的頁(yè)面【詩(shī)書畫唱】
3、創(chuàng)建一個(gè)query.jsp頁(yè)面,創(chuàng)建Product商品類(包含名稱,價(jià)格和進(jìn)貨日期),在這個(gè)頁(yè)面中創(chuàng)建一個(gè)List<Product>集合,通過轉(zhuǎn)發(fā)方式跳轉(zhuǎn)到result.jsp頁(yè)面,在result.jsp頁(yè)面中(注意不是后臺(tái)打印,是頁(yè)面上顯示)顯示商品的所有信息。


<%@page import="com.SSHC.Product"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html;
?charset=UTF-8"
pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()
? ? +path+"/";
? ? List<Product> list = new ArrayList<Product>();
??
? ? request.getRequestDispatcher("result.jsp")
? ? .forward(request, response);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML?
4.01 Transitional//EN">
<html>
<head>

<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
</body>
</html>


<%@page import="com.SSHC.Product"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html;
?charset=UTF-8" pageEncoding="UTF-8"%>
<%
? ? String path = request.getContextPath();
? ? String basePath = request.getScheme()+"://"
? ? +request.getServerName()+":"+request.getServerPort()
? ? +path+"/";
? ? List<Product> list = new ArrayList<Product>();
? ? String []arrName={"詩(shī)書畫唱CD1","詩(shī)書畫唱CD2","詩(shī)書畫唱CD3"};
? ? ? ?Double []arrPrice={6.66,6.66,6.66};
? ? ? ?String []arrJinHuoRiQi={"2020/9/3","2020/9/4","2020/9/5"};
? ? ? ?for(int i=0;i<arrName.length;i++){
? ? ? ? Product p= new Product();
? ? ? ?p.setName(arrName[i]);
? ? ? ?p.setPrice(arrPrice[i]);
? ? ? ?p.setJinHuoRiQi(arrJinHuoRiQi[i]);
? ? ? ?list.add(p);
? ? ? ?}
? ?
%>
<!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=ISO-8859-1">
<title>詩(shī)書畫唱</title>
</head>
? ?<body>
<table border="1">
<tr>
<th>商品名稱</th>
<th>商品價(jià)格</th>
<th>商品進(jìn)貨日期</th>
</tr>
<%
? ? ? ? ? ? ? ? for(int i = 0;i < list.size();i ++) {
? ? ? ?
? ? ? ? ? ? ? ? Product pro = list.get(i);
? ? ? ? ? ? %>
<tr>
<td><%=pro.getName() %></td>
<td><%="¥" + pro.getPrice() %></td>
<td><%=pro.getJinHuoRiQi() %></td>
</tr>
<%
? ? ? ? ? ? ? ? }
? ? ? ? ? ? %>
</table>
</body>
</html>


package com.SSHC;
public class Product {
? ? private String name;
? ? private Double price;
? ? private String jinHuoRiQi;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getJinHuoRiQi() {
return jinHuoRiQi;
}
public void setJinHuoRiQi(String jinHuoRiQi) {
this.jinHuoRiQi = jinHuoRiQi;
}
}


4、設(shè)計(jì)一個(gè)友情鏈接的頁(yè)面,這個(gè)頁(yè)面有一個(gè)列表,能夠跳轉(zhuǎn)到指定的網(wǎng)站去。
淘寶網(wǎng)
京東網(wǎng)
貓撲網(wǎng)
百度網(wǎng)

<%@ 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>Insert title here</title>
</head>
<body>
下面是用超鏈接的方法跳轉(zhuǎn)到指定的網(wǎng)站:<br/>
<h1>友情鏈接:</h1>
<a href="http://www.taobao.com">淘寶網(wǎng)</a>
<a href='http://www.jd.com'>京東網(wǎng)</a>
<a href='http://www.mop.com'>貓撲網(wǎng)</a>
<a href='http://www.baidu.com'>百度網(wǎng)</a>
</body>
</html>



