第一步:这个页面事先建好 form.html ,首先会运行这个页面提交username数据
<form action=" formaction " method="post">
<input type=text name=" username ">
<input type="submit" value="submit">
</form>
第二步,建立好模板文件show.ftl
<html><body>${username}</body></html>
第三步:建立 formaction 对应的处理类FormAction.java,主要源码如下:
public class FormAction{
private String username; // 省略set和get方法
public String execute(){
Map root = new Map();
root.put("username",username);
Writer out = new OutputStreamWriter(new OutputStream(new File(" show.html ")));
//注:省略获取freemarker环境变量configuration的代码
Template template = configuration.getTemplate("show.ftl")
template.process(root,out);
return "success";
}
}
第四步,struts.xml中设置好对应关系
<action name="formaction" class="FormAction">
<result>show.html</result>
</action>
<form action=" formaction " method="post">
<input type=text name=" username ">
<input type="submit" value="submit">
</form>
第二步,建立好模板文件show.ftl
<html><body>${username}</body></html>
第三步:建立 formaction 对应的处理类FormAction.java,主要源码如下:
public class FormAction{
private String username; // 省略set和get方法
public String execute(){
Map root = new Map();
root.put("username",username);
Writer out = new OutputStreamWriter(new OutputStream(new File(" show.html ")));
//注:省略获取freemarker环境变量configuration的代码
Template template = configuration.getTemplate("show.ftl")
template.process(root,out);
return "success";
}
}
第四步,struts.xml中设置好对应关系
<action name="formaction" class="FormAction">
<result>show.html</result>
</action>