struts2_模型驱动
?一.注意点
二.案例创建实体类User: <span style="color: #0000ff">import<span style="color: #000000"> com.opensymphony.xwork2.ModelDriven;
<span style="color: #0000ff">public <span style="color: #0000ff">class<span style="color: #000000"> User{
创建实现ModelDriven接口的action类UserModelAction: <span style="color: #0000ff">public <span style="color: #0000ff">class UserModelAction <span style="color: #0000ff">implements<span style="color: #000000"> ModelDriven{
<span style="background-color: #33cccc"> User user<span style="background-color: #33cccc">=<span style="color: #0000ff">new<span style="color: #000000"><span style="background-color: #33cccc"> User(); @Override <span style="color: #0000ff">public<span style="color: #000000"> Object getModel() { <span style="color: #008000">//<span style="color: #008000"> TODO Auto-generated method stub <span style="background-color: #33cccc"><span style="color: #0000ff">return<span style="color: #000000"><span style="background-color: #33cccc"> user; } <span style="color: #0000ff">public<span style="color: #000000"> String execute(){ System.out.println(user.getUsername()+<span style="color: #000000">user.getPassword()); <span style="color: #0000ff">return<span style="color: #000000"> Action.SUCCESS; } } 提交表单页面编写(关键代码):
用户名:<
密 码:<
<
struts.xml <span style="color: #0000ff"><! <span style="color: #ff00ff">DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "struts-2.0.dtd"<span style="color: #0000ff">> <span style="color: #0000ff"><<span style="color: #800000">struts<span style="color: #0000ff">> web.xml文件(关键代码)
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |