struts是一个MVC框架(Framwork),用于快速开发java Web应用。struts实现的重点在C(Controller),包括ActionServlet/RequestProcessor和我们定制的Action。Struts几乎没有设计M(Model)。
第一步:去官网下载struts的jar包,导入项目中
第二步:创建并编写struts.xml文件
第三步:配置web.xml(配置filter)
第四步:编写action类,并配置到struts.xml中
1、提交表单时,action的路径为在struts.xml中配置的action的name.action
2、action如何接收到表单提交的数据:
1)如果是单个String,使action中的成员变量名称和表单<input>的name完全一样并设置setter方法,
比如,<input type="text" name="username">,则在action中也设置一个private String username;并设置其getter,setter方法。
2)如果是JavaBean对象,则
用户名:<input type = "text" name = "user.username" /><br/>
密码:<input type = "password" name= "user.password"><br/>,同时在action中创建一个同名成员变量。