struts 2フロントパラメータを受信する3つの方法
2572 ワード
01.public class GetRequestParameterAction extends ActionSupport {
02.
03. private String bookName;
04. private String bookPrice;
05.
06. public String getBookName() {
07. return bookName;
08. }
09.
10. public void setBookName(String bookName) {
11. this.bookName = bookName;
12. }
13.
14. public String getBookPrice() {
15. return bookPrice;
16. }
17.
18. public void setBookPrice(String bookPrice) {
19. this.bookPrice = bookPrice;
20. }
21.
22.
23. public String execute() throws Exception{
24.
25.
26. // : Action , OGNL
27.
28. System.out.println(" , Action , OGNL :");
29. System.out.println("bookName: "+this.bookName);
30. System.out.println("bookPrice: " +this.bookPrice);
31.
32.
33. // : Action ActionContext parameterMap :
34. ActionContext context=ActionContext.getContext();
35. Map parameterMap=context.getParameters();
36.
37. String bookName2[]=(String[])parameterMap.get("bookName");
38. String bookPrice2[]=(String[])parameterMap.get("bookPrice");
39.
40. System.out.println(" , Action ActionContext parameterMap :");
41. System.out.println("bookName: " +bookName2[0]);
42. System.out.println("bookPrice: " +bookPrice2[0]);
43.
44.
45. // : Action HttpServletRequest , request.getParameter
46. HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
47.
48. String bookName=request.getParameter("bookName");
49. String bookPrice=request.getParameter("bookPrice");
50.
51. System.out.println(" , Action HttpServletRequest , request.getParameter :");
52. System.out.println("bookName: " +bookName);
53. System.out.println("bookPrice: " +bookPrice);
54. return SUCCESS;
55.
56. }
57.
58.}