개발시 임시로 사용했던 http post sample page 내용을 공유해본다.
아래의 예제에서 쓰이는 Post variable은 pk, title 그리고content 이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | <%@ page language = "java" contentType="text/html; charset=EUC-KR" %> <%@ page pageEncoding = "EUC-KR" %> <%@ page import="java.lang.*" %> <%@ page import="java.util.*" %> <%@ page import="java.net.*" %> <%@ page import="java.io.*" %> <% // Set Query URL url = new URL("http://127.0.0.1:8090/insertdb"); URLConnection uc = url.openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); // add the query string // For example: String query = "apikey=APIKEY&member=joe&pw=secret"; String query = "pk=123&title=sample_title&content=sample_content"; PrintWriter pw = new PrintWriter(uc.getOutputStream()); pw.println(query); pw.close(); // get the input from the request BufferedReader in = new BufferedReader( new InputStreamReader(uc.getInputStream())); String result = in.readLine(); in.close(); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Email Search Test Page</title> <style type="text/css"> body, td, input, textarea, select { font-family: Verdana, 맑은고딕; font-size: 9pt; color: #000000; } input, textarea, select { border: 1px solid #DDDDDD; } a { color: #FF3333; text-decoration: none; } a:visited { color: #FF3333; text-decoration: none; } a:hover { color: #FF3333; text-decoration: underline; } </style> <script language="javascript"></script> </head> <body> <h1>Http request Result</h1> <%= result %> </body> </html> |
'Programming' 카테고리의 다른 글
Frequently used(referred) Python code (0) | 2013.05.24 |
---|---|
Java sample code of random string generator (0) | 2013.05.15 |
String vs StringBuffer vs StringBuilder in Java (0) | 2013.05.15 |
Removing BOM in Java (0) | 2013.04.29 |
자바 프로젝트 내에서의 빌드 버전 관리 (ant) (0) | 2013.04.24 |
댓글