JavaWeb-JSP的傳值接收值按所傳數顯示圖片
阿新 • • 發佈:2018-10-31
題目分析:
題目分析:
從第一個jsp中傳值,然後第二個jsp根據傳過來的數顯示圖片,數為多少就顯示多少個圖片
第一個jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>img</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> <form action="/FridayJob/Task/Task03/img_action.jsp" method="post"> <input type="text" name="num"><input type="submit"> </form> </body> </html>
第二個jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>img_action</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> <h1>傳值接收值按所傳資料顯示圖片</h1> <% int number = Integer.parseInt(request.getParameter("num")); %> <% for (int i = 0; i < number; i++) { %> <img src="/FridayJob/Task/Task03/panda.png"> <% } %> </body> </html>