j2ee学习笔记

xiaoxiao2021-02-28  9

本文主要讲一下学struts首先应该做什么,如何做

一、首先,先弄清什么是struts

struts是一个MVC框架(Framwork),用于快速开发java Web应用。struts实现的重点在C(Controller),包括ActionServlet/RequestProcessor和我们定制的Action。Struts几乎没有设计M(Model)。

二、如何使用struts

第一步:去官网下载struts的jar包,导入项目中

第二步:创建并编写struts.xml文件

第三步:配置web.xml(配置filter)

第四步:编写action类,并配置到struts.xml中

三、使用struts的一些说明

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中创建一个同名成员变量。

转载请注明原文地址: https://www.6miu.com/read-2450040.html

最新回复(0)