์›น๋ธŒ๋ผ์šฐ์ €์—์„œ ์›น์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์€ ๋‘๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. GET๋ฐฉ์‹๊ณผ POST๋ฐฉ์‹์ด ๊ทธ๊ฒƒ์ด์ฃ .  

RESTFUL์—์„œ๋Š” ๋” ๋งŽ์€ ๋ฐฉ์‹์ด ์žˆ์ง€๋งŒ ์—ฌ๊ธฐ์„œ๋Š” GET ๊ณผ POST์— ๋Œ€ํ•ด์„œ๋งŒ JSP๋กœ ํ•ธ๋“ค๋ง ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

JSP๋ฅผ ์ด์šฉํ•œ FORM ๋ฐ์ดํ„ฐ ์ฝ๊ธฐ

์›น๋ธŒ๋ผ์šฐ์ €์—์„œ form๋ฐ์ดํƒ€๋ฅผ ์ด์šฉํ•ด์„œ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด JSP์—์„œ ๊ทธ form ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์†Œ๋“œ๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

  • getParameter(): You call request.getParameter() method to get the value of a form parameter.

  • getParameterValues(): Call this method if the parameter appears more than once and returns multiple values, for example checkbox.

  • getParameterNames(): Call this method if you want a complete list of all parameters in the current request.

  • getInputStream(): Call this method to read binary data stream coming from the client.


URL์„ ์ด์šฉํ•œ GET๋ฐฉ์‹ ์˜ˆ์ œ

์•„๋ž˜ URL์€ get๋ฐฉ์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์›น์„œ๋ฒ„๋กœ ๋„˜๊ฒจ์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. first_name์ด๋ผ๋Š” ๋ณ€์ˆ˜์— "๊ธธ๋™"๋ผ๋Š” ๊ฐ’์ด ๋“ค์–ด์žˆ๊ณ  "ํ™"์ด๋ผ๋Š” ๋ณ€์ˆ˜์— ALI๋ผ๋Š” ๊ฐ’์ด ๋“ค์–ด์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

http://localhost:8080/main.jsp?first_name=๊ธธ๋™&last_name=ํ™

 

๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜๋Š” main.jsp ์˜ ์†Œ์Šค์ž…๋‹ˆ๋‹ค.  getParameter() ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•ด์„œ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋„˜๊ฒจ์ค€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ค๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

<html> <head> <title>Using GET Method to Read Form Data</title> </head> <body> <center> <h1>Using GET Method to Read Form Data</h1> <ul> <li><p><b>First Name:</b> <%= request.getParameter("first_name")%> </p></li> <li><p><b>Last Name:</b> <%= request.getParameter("last_name")%> </p></li> </ul> </body> </html>

์ด์ œ ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ http://localhost:8080/main.jsp?first_name=๊ธธ๋™&last_name=ํ™ ์„ ํƒ€์ดํ•‘ํ•ด์„œ ์›น์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ํ•ด๋ณด์„ธ์š”. ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค. 

 

Using GET Method to Read Form Data

  • First Name: ๊ธธ๋™

  • Last Name: ํ™


Form์„ ์ด์šฉํ•œ GET ๋ฐฉ์‹ ์˜ˆ์ œ

์•„๋ž˜๋Š” HTML ํƒœ๊ทธ ์ค‘์—์„œ formํƒœ๊ทธ๋ฅผ ์ด์šฉํ•œ get๋ฐฉ์‹ ์š”์ฒญ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค. 

<html> <body> <form action="main.jsp" method="GET"> First Name: <input type="text" name="first_name"> <br /> Last Name: <input type="text" name="last_name" /> <input type="submit" value="Submit" /> </form> </body> </html>

์œ„ ์†Œ์Šค๋ฅผ Hello.htmํŒŒ์ผ์— ์ž‘์„ฑํ•˜๊ณ  <Tomcat-installation-directory>/webapps/ROOT ๋””๋ ‰ํ† ๋ฆฌ์— ๋„ฃ์–ด์ฃผ์„ธ์š”. 

http://localhost:8080/Hello.htm ๋ฅผ ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ ์š”์ฒญํ•˜๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ํ™”๋ฉด์— ๋ณด์—ฌ์ง‘๋‹ˆ๋‹ค.  


 

์ด์ œ ๋นˆ๋ฐ•์Šค์— ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ  submit๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ๋ณด์„ธ์š”. ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด main.jsp์— ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๊ณ  ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ main.jsp์—์„œ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค 

์ฒ˜๋ฆฌ๋œ ๊ฒฐ๊ณผ๋Š” ์œ„์—์„œ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ์™€ ๋™์ผํ•˜๊ฒŒ ๋‚˜์˜ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

 

Reference : http://www.tutorialspoint.com/jsp/jsp_form_processing.htm