English 中文(简体)
如何操作要求参数
原标题:How Struts 2 handle request parameters
  • 时间:2012-01-13 00:13:52
  •  标签:
  • struts2

我记得,我从某个地方读过了这句话,但至今仍然不知。

审议以下设想:

<action name="doSomething" class="com.domain.MyAction" method="myMethod">              
    </action> 

以及

 public class MyAction extends ActionSupport{

      public String myMethod(){
       private String param;

       }
       //getter
       //setter
    }

然后通过网页I:POST o GET: area/doSomething?param=hello

我能够使用以下任何方法收回“半”价值,无论这些方法是否相同?

this.getParam();
(String)request.getParameter("param");
(String)request.getSession.getAttribute("param");

如果是的话,那么入侵者将总是将申请参数纳入http://_session?

最佳回答

各项要求使用接收器和设定要求参数,以在行动中予以通过。

 public class MyAction extends ActionSupport{

   private String param;
   public void setParam(String p){ param=p;  }
   public String getParam() { return param; }

  public String myMethod(){
      System.out.println("Got the request parameter automatically just by having a getter and setter for that parameter " + param);
   }
}
问题回答

暂无回答




相关问题
Getting sitemesh to work with struts2

I m trying to integrate sitemesh into my struts2 app, but i m finding that it s not making any difference and isn t showing any errors (or anything sitemesh related at all) in the logs. I ve started ...

Struts Action Validation

Hey People. I have been recently validating Struts 2 actions. In One of my action class, the save method to be precise must have two id s. That is an assessmenttype id and a course id. this is what is ...

struts2 action not calling properly

On default I want my struts2 app to forward to an action: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"...

How to validate a select tag in struts 2 framework

I am a newbie into programming and i am currently employed as a junior programmer. I am currently having some problems validating the select tags in one of my forms. What i actually trying to do is to ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

热门标签