java小毛孩

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            1 Posts :: 1 Stories :: 1 Comments :: 0 Trackbacks
           

          請用struts完成以下描述的功能;

          用戶從IE客戶端輸入字符串Hello,關提交給HelloAction,在Action中給Hello轉換成“hello world!”并顯示給用戶。

          下面為處理流程的配置文件:

          hello.jsp ——input—— HelloAction.java —— forward——Sayhello.jsp

          <action path="HelloWorld" type="hello.HelloAction" name="HelloForm" scope="request" validate="true" input="hello.jsp">

          <forward name="SayHello" path="sayhello.jsp"/>

          <action>

          表單HelloForm.java

          public class HelloForm{

                 private String content;

                 public String getContent(){

                        return this.content;

                 }

                 public void setContent(String content){

                        this.content = content;

                 }

          }

          請實現hello.jsp , HelloAction.java ,sayhello.jsp

          posted on 2009-03-25 21:36 無印之路 閱讀(377) 評論(1)  編輯  收藏

          Feedback

          # re: 一道關于Struts的面試題 2009-03-26 17:40 無印之路
          做出來了。
          Hello.jsp
          <s:from action=”HelloAction” mothod=”post”>
          <s:textfield name="helloform.content"></s:textfield>
          <s:submit value="提交"></s:submit>
          </s:from>

          HelloAction.java
          import javax.servlet.http.HttpServletRequest;
          import org.apache.struts2.ServletActionContext;

          import com.opensymphony.xwork2.ActionSupport;

          public class HelloAction extends ActionSupport {

          private HelloForm helloform;

          public HelloForm getHelloform() {
          return helloform;
          }
          public void setHelloform(HelloForm helloform) {
          this.helloform = helloform;
          }

          public String input(){
          HttpServletRequest request = ServletActionContext.getRequest();

          if(helloform.getContent().equals("Hello")){
          String input=helloform.getContent();
          request.setAttribute("input","hello world!");
          }else{
          request.setAttribute("input","輸入錯誤!");
          }
          System.out.println(helloform.getContent());
          return SUCCESS;
          }
          }

          Sayhllo.jsp

          <body>
          <%=request.getAttribute("input") %>
          </body>
            回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 逊克县| 高安市| 额济纳旗| 定兴县| 葫芦岛市| 青铜峡市| 甘洛县| 喀什市| 万荣县| 惠东县| 茂名市| 遂溪县| 湘潭市| 孟津县| 唐河县| 虞城县| 潍坊市| 宜丰县| 珲春市| 嵊州市| 张家港市| 图片| 拜城县| 武宁县| 黄骅市| 砚山县| 邵武市| 洛川县| 公主岭市| 永兴县| 额尔古纳市| 瓮安县| 红桥区| 枣阳市| 丹凤县| 宽城| 新巴尔虎左旗| 昌黎县| 东乌珠穆沁旗| 文登市| 浠水县|