欢迎光临散文网 会员登陆 & 注册

Java web:转发方式跳转,页面上显示,友情链接的页面【诗书画唱】

2020-09-06 10:24 作者:诗书画唱  | 我要投稿


3、创建一个query.jsp页面,创建Product商品类(包含名称,价格和进货日期),在这个页面中创建一个List<Product>集合,通过转发方式跳转到result.jsp页面,在result.jsp页面中(注意不是后台打印,是页面上显示)显示商品的所有信息。








<%@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={"诗书画唱CD1","诗书画唱CD2","诗书画唱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>诗书画唱</title>

</head>


   <body>


<table border="1">


<tr>


<th>商品名称</th>


<th>商品价格</th>


<th>商品进货日期</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、设计一个友情链接的页面,这个页面有一个列表,能够跳转到指定的网站去。

淘宝网

京东网

猫扑网

百度网


<%@ 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>

下面是用超链接的方法跳转到指定的网站:<br/>

<h1>友情链接:</h1>

<a href="http://www.taobao.com">淘宝网</a>


<a href='http://www.jd.com'>京东网</a>


<a href='http://www.mop.com'>猫扑网</a>


<a href='http://www.baidu.com'>百度网</a>


</body>

</html>


Java web:转发方式跳转,页面上显示,友情链接的页面【诗书画唱】的评论 (共 条)

分享到微博请遵守国家法律