๋กœ์ผ“๐Ÿพ
article thumbnail

 

@RequestParam ์• ๋„ˆํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ’์„ ์–ป๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

 


l ์˜ˆ์‹œ

 

loginForm.jsp

๋‹ค์Œ๊ณผ ๊ฐ™์€ view์—์„œ ์•„์ด๋””๋ฅผ kbj, ์ด๋ฆ„์„ ๊น€๋ณ‘์ค€์œผ๋กœ ์ž…๋ ฅํ•˜๊ณ  ์ „์†กํ•ฉ๋‹ˆ๋‹ค. 

 

package com.spring.ex02;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller("loginController")
@RequestMapping(value="/test")
public class LoginController {
	@RequestMapping(value="/loginForm.do")
	public ModelAndView loginForm(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView();
		mv.setViewName("loginForm");
		return mv;
	}
	
	@RequestMapping(value="/login.do", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView login(@RequestParam("userID") String userID, @RequestParam("userName") String userName
			,HttpServletRequest request, HttpServletResponse response) throws Exception{
		request.setCharacterEncoding("utf-8");
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("result");
		
		//String userID = request.getParameter("userID");
		//String userName = request.getParameter("userName");
		
		mv.addObject("userID", userID);
		mv.addObject("userName", userName);
		
		return mv;
	}
}

 

๋‘๋ฒˆ์งธ ๋ฉ”์„œ๋“œ์—์„œ 

@RequestParam("userID") String userID //input์˜ value ๊ฐ’์ด ๊ฐ๊ฐ userID์™€ userName์ž…๋‹ˆ๋‹ค.
@RequestParam("userName") String userName

 

๊ฐ™์ด ๋˜์–ด์žˆ๋Š”๋ฐ ์ € ์• ๋„ˆํ…Œ์ด์…˜์„ ์ด์šฉํ•˜์—ฌ ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๊ฐ’์ด ์ถœ๋ ฅ๋œ๊ฒƒ์„ ๋ณด์‹ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

request.getParameter("userID")๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒํ™ฉ์— ๋งž๊ฒŒ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

 

์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์งˆ๋ฌธ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.

 

"๋‚œ ๋ฐ˜๋“œ์‹œ ๋ฐฑ์—”๋“œ ์™•์ด ๋ ๊ฑฐ์•ผ"

profile on loading

Loading...