posts - 61,  comments - 2033,  trackbacks - 0
 

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

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


网站导航:
 
<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用链接

留言簿(82)

随笔分类(59)

文章分类(21)

相册

收藏夹(40)

GoodSites

搜索

  •  

积分与排名

  • 积分 - 1270628
  • 排名 - 22

最新评论

阅读排行榜