본문 바로가기
개발/jsp

hashmap,foreach,구구단,list

by 카앙구운 2015. 10. 13.
728x90
반응형

hashMap을 이용,구구단 및 list만들기


<%@page import="java.util.List"%>

<%@page import="java.util.ArrayList"%>

<%@page import="java.util.HashMap"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!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>


<c:forEach var="i" begin="1" end="10">

${i}

</c:forEach>

<br>

<c:forEach var="i" begin="1" end="10" step="2">

${i}

</c:forEach>

<br>

<c:set var="sum" value="0"/>

<c:forEach var="i" begin="1" end="100" step="2">

<c:set var="sum" value="${sum+1}"/>

</c:forEach>

${sum}


<br>

<c:set var="su" value="4"/>


<c:forEach var="i" begin="1" end="9">

<c:set var="hap" value="${su*i}" />

${su} X ${i}= ${hap}

</c:forEach>

<br>


<c:forEach var="i" begin="2" end="9">

<c:forEach  var="j" begin="1" end="9">

${i} X ${j} = ${i*j}

<br>

</c:forEach>

<br>

</c:forEach>


<%

int [] intArr =new int[]{1,2,3,4,5};

int len=intArr.length;

for(int a=0;a<len;a++){

out.print(intArr[a]+"&nbsp;");

}

%>

<br>

<c:set var="intArray" value="<%=intArr%>" />

<c:forEach var="i" items="${intArray}">

${i}

</c:forEach>


<c:forEach var="i" items="${intArray}" begin="2" end="4" varStatus="s">

${i}, ${s.index}, ${s.count }/

</c:forEach>

<br>

<br>


<%

HashMap<String, Object> mapData=new HashMap<String,Object>();

mapData.put("title", "java교육");

mapData.put("name","홍길동");


%>

<c:set var="map" value="<%=mapData%>"/>


<c:forEach var="i" items="${map}">

${i.key}=${i.value}<br> 

</c:forEach>

<br>

<br>

<%

List listArray=new ArrayList();


HashMap<String,Object> boardData=new HashMap<String,Object>();

boardData.put("title","javass교육");

boardData.put("name","홍길동");

boardData.put("rdate","2015-10-12 12:23:20");

listArray.add(boardData);

boardData=new HashMap<String,Object>();

boardData.put("title","PHP프로젝트");

boardData.put("name","나크네");

boardData.put("rdate","2015-10-11 12:23:20");

listArray.add(boardData);

%>

<%=listArray %>


<c:set var="map2" value="<%=listArray %>"/>

<table border="0">

<tr><td height="1" colspan="3" bgcolor="#ccccccc"></td></tr>

<tr>

<td>제목</td><td>이름</td><td>날짜</td>

</tr>

<tr><td height="1" colspan="3" bgcolor="#ccccccc"></td></tr>

<c:forEach var="result" items="${map2}" varStatus="status">

<tr>

<td width="150"><c:out value="${fn:substring(result.title,0,5)}"/>....</td>

<td width="100"><c:out value="${result.name}"/></td>

<td width="100"><c:out value="${fn:substring(result.rdate,0,10)}"/></td>

</tr>

<tr><td height="1" colspan="3" bgcolor="#ccccccc"></td></tr>

</c:forEach>

</table>

</body>

</html>










728x90
반응형

'개발 > jsp' 카테고리의 다른 글

servlet,db  (0) 2015.10.13
Servlet  (0) 2015.10.13
jstl forTokens,formatNumber  (0) 2015.10.13
jstl 함수 사용 방법  (0) 2015.10.08
jstl 변수 선언  (0) 2015.10.08

댓글