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 无印之路 阅读(343) 评论(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>
  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: