Several places to pay attention to when using struts2 tags

1. The s tag of struts2 is used directly on the jsp page, which must be filtered by FileterDispatcher, otherwise an error 
org.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter will always be reported . Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. 

Solution: 

Xml code   Favorite code
  1. <filter>  
  2.         <filter-name>struts2</filter-name>  
  3.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  
  4.     </filter>  
  5.     <filter-mapping>  
  6.         <filter-name>struts2</filter-name>  
  7.         < url-pattern > *.action </ url-pattern > <!--Filter main action -->  
  8.     </filter-mapping>  
  9.     <filter-mapping>  
  10.         <filter-name>struts2</filter-name>  
  11.         <url-pattern>*.jsp</url-pattern>  
  12. <!--Because if the struts tag is used on the jsp page, it must be filtered by the FilterDispacher, so that the configuration can ensure that all jsp go through the FilterDispatcher, otherwise, an action address must be configured for each jsp write-->  
  13.     </filter-mapping>  






2. In the process of using the struts tag, some table and td tags will be generated and the tags will wrap automatically. The removal method is as follows: 
1. Add theme="simple" 
<s:textfield name="userName" theme=" to the tag simple" ></s:textfield>--the use of ordinary text fields 
2. Configure in the struts.xml file: 
<constant name="struts.ui.theme" value="simple" /> 
This will remove the tag And solve the problem of word wrapping. 

3. The problem that the ognl expression cannot directly access the static method.
 

Today, the method is called directly with ognl on the page: 

<s:property value="@com.DateUtil@getTimeArray()"/> to get the time, but the method cannot be accessed. 

After copying this code to another project, the method can be called normally. 

I checked the online information, and the reasons are as follows. Some struts2 configuration items include a configuration item named struts.ognl.allowStaticMethodAccess which is false by default; 

the solution: 
1
Configure in struts.properties: 

Xml code   Favorite code
  1. struts.ognl.allowStaticMethodAccess=true  



Or 

configure in struts.xml: 

Xml code   Favorite code
  1. <constant name="struts.ognl.allowStaticMethodAccess" value="true" />  

 

2. Change your method to static

 

public static List kechengSelect()
{
String sql="from kecheng where del='no'" ;
List kechengList=kechengDAO.getHibernateTemplate().find(sql);
return kechengList;
}

可直接调用方法: 
eg: <a 
                          href="http://v.t.sina.com.cn/share/share.php?url=http://<s:property value="couponDetailVO.cityGbName"/>.koubei.com/youhuiquan/<s:property value="couponDetailVO.id"/>&title=<s:property value="@java.net.URLEncoder@encode(couponDetailVO.name,'UTF-8')"/>" 
                          class="k2-icon-node-m k2-icon-s-sina" target="_blank">分享到新浪微博</a> 
问题解决 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326172034&siteId=291194637