Struts2

在struts.xml文件中,通过<action>元素对Action进行配置。<action>元素常用的属性有如下几个:

  1. name  该属性用来指定客户端发送请求的地址映射名称

  2. class  该属性用来指定进行业务逻辑处理的Action的名称

  3. method  该属性用来指定进行业务逻辑处理的Action中的方法名称

<action name="Action名称" class="包名.Action名称" method="方法名称">

通配符的使用规则

在jsp文件中<action>元素中配置name 和 method属性,之后在struts.xml文件中使用通配符。

使用通配符

index.jsp文件中 <s:form action="book_addBook" namespace="/" method="post">

  method有get和post方法。

    get方法

    post方法

struts.xml文件中<action name="book_*" class="com.demo1.LoginAction" method="{1}">

Struts2标签库

通过下面代码就可以导入Struts2标签库

   <%@ taglib prefix="s" uri="/struts-tags"%>

  其中taglib元素表明引入标签,类似Java中import关键字。

  prefix="s"指定引入名称,就像在Java中获得一个对象名,在调用时使用<s:xxx>就可以了。

  uri="/struts-tags"表示标签库的路径。

 

posted @ 2017-03-23 16:18  章朔  阅读(126)  评论(0编辑  收藏  举报