출처 : jsp2.2 웹프로그래밍 저자 최범균
위 책에서 jsp관련 내용을 연습하면서 올리고 있습니다. 괜찮은책입니다.
[결과]
Thermometer.java
package model;
import java.util.*;
public class Thermometer {
private Map<String,Double> locationCelsiusMap = new HashMap<String,Double>();
public void setCelsius(String location, Double value){
locationCelsiusMap.put(location,value);
}
public Double getCelsius(String location){
return locationCelsiusMap.get(location);
}
public Double getFahrenheit(String location){
Double celsius = getCelsius(location);
if(celsius == null){
return null;
}
return celsius.doubleValue()*1.8+32.0;
}
public String getInfo(){
return "온도계 변환기 1.1";
}
}
thermometer.jsp
<%@page import="model.Thermometer"%>
<%@ page contentType="text/html; charset=utf-8"
%>
<%
Thermometer thermometer = new Thermometer();
request.setAttribute("t", thermometer);
%>
<!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>온도 변환 예제</title>
</head>
<body>
${t.setCelsius('서울',27.3) }
서울 온도 : 섭씨 ${t.getCelsius('서울')}도/화씨${t.getFahrenheit('서울') }
<br/>
정보 : ${t.info}
</body>
</html>