1. HttpServletRequest
[Controller]
@RequestMapping(value="/sendTest", method=RequestMethod.POST)
public String HttpServletRequestTest(HttpServletRequest req) {
System.out.println("== HttpServletRequest Test ==");
System.out.println(req.getParameter("id"));
System.out.println(req.getParameter("pw"));
return "view/main";
}
[html]
<form action="/sendTest" method="post">
<input type="text" name="id"/>
<input type="password" name="pw"/>
<input type="submit" value="send"/>
</form>
2. Map
[Controller]
@RequestMapping(value="/sendTest", method=RequestMethod.POST)
public String getMap(@RequestParam Map<String, Object> map) {
System.out.println("== Map Test ==");
System.out.println(map.get("id"));
System.out.println(map.get("pw"));
return "view/main";
}
[html]
<form action="/sendTest" method="post">
<input type="text" name="id"/>
<input type="password" name="pw"/>
<input type="submit" value="send"/>
</form>
3. VO(Entity)
[VO]
@Entity
@Getter
@Setter
@Table(name ="member")
public class Member {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private String id;
private String password1;
}
[Controller]
@RequestMapping(value="sendTest", method=RequestMethod.POST)
public String getVO(Member vo) {
System.out.println("== VO(Entity) Test ==");
System.out.println(vo.getId());
System.out.println(vo.getPassword1());
return "view/main";
}
[html]
<form action="/sendTest" method="post">
<input type="text" name="id"/>
<input type="password" name="password1"/>
<input type="submit" value="send"/>
</form>
4. arrayList (수정하기!!!)
[Controller]
@RequestMapping(value="sendTest", method=RequestMethod.POST)
public String ArrayListTest(@RequestParam ArrayList<String> array) {
System.out.println("== ArrayList Test==");
for(int i=0, n=array.size(); i<n; i++) {
System.out.println(array.get(i));
}
return "view/main";
}
[html]
<form action="/sendTest" method="post">
<input type="text" name="array"/>
<input type="password" name="array"/>
<input type="submit" value="send"/>
</form>
'JAVA > 1' 카테고리의 다른 글
415 error (0) | 2022.05.06 |
---|---|
JAVA log 정리 (0) | 2022.04.30 |
[intelliJ IDEA] try-catch 단축키 (0) | 2021.12.27 |
Mac OS(m1) JAVA | Maven | Tomcat | IntelliJ | Spring 설치 및 설정 (0) | 2021.12.21 |
Mac OS(m1) JAVA | Maven | Tomcat | VScode | Spring 설치 및 설정(수정 중...............!!!!) (0) | 2021.10.29 |