본문 바로가기

기존카테고리/Spring_문법

Parameter값 받기 - 기초(@RequestParam)

package com.test.customTag;


import javax.servlet.http.HttpServletRequest;


import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;


@Controller

@RequestMapping("users")

public class userController {

@RequestMapping("input")

public String userInput(){

return "/users/input";

}

@RequestMapping("inputUp")

public String userInputUp(@RequestParam("userId") String userId, @RequestParam("userName") String userName, Model model){

// String userId = request.getParameter("userId");

// String userName = request.getParameter("userName");

model.addAttribute("userId", userId);

model.addAttribute("userName", userName);

return "/users/inputUp";

}

}



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>회원정보</h2>
<form method="post" action="inputUp">
아이디: <input type="text" name="userId" /> <br />
이름: <input type="text" name="userName" />
<input type="submit" value="전송" />
</form>

</body>
</html>



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>회원정보</h2>
아이디: ${userId}<br>
이름: ${userName}
</body>
</html>


'기존카테고리 > Spring_문법' 카테고리의 다른 글

스프링 DI(Dependency Injection) 1  (0) 2017.07.23
Parameter값 받기 - 실전(Command객체)  (0) 2017.07.13
Parameter값 받기 - 기초(HttpServletRequest)  (0) 2017.07.13
Class Mapping  (0) 2017.07.13
Model 과 ModelAndView  (0) 2017.07.13