struts2

查看栈

<%@ taglib prefix ="s" url="/sturts-tags" %>


<s:debug></s:debug>

  取出

OGNL方法

<s:property value=“[数字].名”>

数字代表开始寻找值的开始位置

action对象默认位于栈顶。

对象map栈

OGNL

<s:poperty values="#session.object.name"></s:poperty>

#域.对象名.属性

EL

${sessipnScop.object.name}

对于表单内的action后缀问题

struts.xml

 <constant name="struts.action.extension" value=","></constant> 

 default.properties描述

### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
### The blank extension allows you to match directory listings as well as pure action names
### without interfering with static resources, which can be specified as an empty string
### prior to a comma e.g. struts.action.extension=, or struts.action.extension=x,y,z,,
struts.action.extension=action,,

 action使用通配符方式

<action name="member_*" class="com.mb.controller.LoginController" method="{1}" >
<result name="success">/member.jsp</result>

使用普通的html标签时

<form action="member_login" method="post">
       
       <input type="text" name="userInfo.username">
 <input type="password" name="userInfo.password">
<input type="submit"/> </form>

  action=“member_login”可以无后缀(因为配置了struts.action.extension为“,”)

使用tag标签时

  <s:form action="member_login" method="POST">
<s:textfield name="userInfo.username" label="用户名" required="true"></s:textfield>
<s:password name="userInfo.password"  label="密码" required="true"></s:password>


     <s:submit value="登录"></s:submit>

        </s:form>

  虽然代码action没有后缀但是在页面生成时变成了

<div title="登录" style="padding:10px;">
        <form id="member_login" name="member_login" action="/MessageBoard/member_login.action" method="POST">
<table class="wwFormTable">
<tr>
    <td class="tdLabel"><label for="member_login_userInfo_username" class="label">用户名:</label></td>
    <td
><input type="text" name="userInfo.username" value="" id="member_login_userInfo_username" required="true"/></td>
</tr>
<tr>
    <td class="tdLabel"><label for="member_login_userInfo_password" class="label">密码:</label></td>
    <td
><input type="password" name="userInfo.password" id="member_login_userInfo_password" required="true"/></td>
</tr>
     <tr>
    <td colspan="2"><div align="right"><input type="submit" id="member_login_0" value="登录"/>
</div></td>
</tr>   
</table></form>

可以看出action请求出现了后缀 。

这时两种方式均有效

类似<constant name="struts.action.extension" value=","></constant> 的修改对struts-tag标签下的form action无影响,struts自动生成action请求连接,struts依旧会回应请求

而html下form标签如果没有配置,默认的话该怎样就怎样,还是需要后缀。

原文地址:https://www.cnblogs.com/nova-/p/3899548.html