2012. 6. 11. 18:27

response.setHeader("Cache-control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);


<META http-equiv="Cache-Control" content="no-cache"/>
<META http-equiv="Expires" content="0"/>
<META http-equiv="Pragma" content="no-cache"/>

http://blog.naver.com/akswnsjd1/60038364745

 

'WebPrograming > JSP' 카테고리의 다른 글

<jsp:include> 팁  (0) 2013.01.18
JSP 달력(CSS적용)  (2) 2012.03.29
Posted by 물색없는세상
2012. 6. 11. 10:49

자바 (JAVA) 랜덤 숫자 생성

 

자바에서 랜덤 숫자를 생성할떄는,  Random 클래스를 이용하여 임의의 정수를 생성할 있습니다.

 

Import 사용

먼저, 다음 코드를 소스 상단에 입력해주세요.

import java.util.Random;

 

 

Random 객체 생성

Random r = new Random();

 

랜덤 정수 생성

int i = r.nextInt(10); // 0~9까지의 랜덤 정수 생성

 

간단 하지요? 이번엔 3~8까지의 랜덤 정수를 생성해봅시다.

int j = r.nextInt(6) + 3; // 3~8까지의 임의 랜덤 정수 생성

 

r.nextInt(6) 0~5까지의 랜덤 정수를 나타냅니다.

거기서 + 3 을 해주면, 3~5까지의 랜덤 정수가 되는거죠

 

 

다음은 10~20까지의 홀수, 정수를 구하는 예제소스 입니다

import java.util.Random;

 

public class cRandom {

 

 

             public static void main(String[] args) {

                           Random r = new Random();

                           int i = 2 * r.nextInt(6) + 10;//10~20 사이의 랜덤 짝수

                           int j = 2 * r.nextInt(5) +11; // 10~20 사이의 랜덤 홀수

                          

                           System.out.println("짝수: " + i + "\n홀수: " + j);

             }

 

}

 

 

자바 (JAVA) 랜덤 숫자 생성 .

 

태클은 환영입니다; 잘못된부분 있으면 지적해주세요.

Copyright  J-NaKiM. All Rights Reserved

 

출처 - http://jnakim.com/10138823939

'ApplicationPrograming > Java' 카테고리의 다른 글

Commons-DbUtils  (0) 2013.03.15
Commons-Fileupload의 한글관련 문제 추가  (0) 2013.03.15
JDOM  (0) 2013.01.31
me2DAY XML Parsing (DOM) - 자바 XML파싱  (0) 2012.07.24
jar파일 실행  (0) 2012.05.04
Posted by 물색없는세상
2012. 5. 4. 18:28

하나의 톰캣에서 2개 이상의 포트로 접속을 하되 결국은 하나의 웹 어플리케이션으로 요청이 들어오도록 하고 싶었다. 입구가 2개있는 하나의 방이라고나 할까....

예를들면 web_test라는 웹 어플리케이션이 있을때
(1) http://localhost:8080/web_test/index.jsp로도 접속하고
(2) http://localhost:9090/web_test/index.jsp로도 접속하고 싶은것이다.

방법은 아주 간단하다.
tomcat의 server.xml을 열어서...

 

<Service name="Catalina">
      <Connector connectionTimeout="20000" port="8080" 
               protocol="HTTP/1.1" redirectPort="8443"/>
      <Connector connectionTimeout="20000" port="9090" 
               protocol="HTTP/1.1" redirectPort="8443"/>
 
      <Engine defaultHost="localhost" name="Catalina">
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
                    resourceName="UserDatabase"/>
          <Host appBase="webapps" autoDeploy="true" name="localhost" 
                    unpackWARs="true" xmlNamespaceAware="false" 
                    xmlValidation="false">
              <Context docBase="web_test" path="/web_test" 
                    reloadable="true" source="여기에소스위치"/>
          </Host>
    </Engine>
</Service>

 

Connector를 추가하면 된다.
들어오는 포트는 8080이나 9090을 사용하되 redirect되는 포트는 둘 다 8443인 것이다.

실험을 해보자면, 일단은 이렇게 생긴 jsp페이지가 필요하다.

 

<%@ 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>Hello, World!!</title>
</head>
<body>
	Host : <%= request.getHeader("Host") %><br/>
	URI : <%= request.getRequestURI() %><br/>
</body>
</html>

 

실험결과
 


 

 


클라이언트의 HTTP헤더를 열어서 어떤 포트로 접속했는지 확인할 수 있다.

 

http://case35.tistory.com/260

Posted by 물색없는세상