`

Struts2 报错

阅读更多

http://wenku.baidu.com/view/e0fa4e3610661ed9ad51f3d0.html  百度文档

 

1.不识别struts2标签:

 严重: Servlet.service() for servlet jsp threw exception
The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
 at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)

 

<filter-mapping>
    
<filter-name>struts2</filter-name>
    
<url-pattern>*.jsp</url-pattern>
</filter-mapping>                                  在web.xml加上这个就好了。

 

2.警告: Error setting expression 'user.name' with value '[Ljava.lang.String;@1cb0cdc'
ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@1cb0cdc)
 at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2219)


<s:textfield name="user.name" label="用户名" cssStyle="width:120px;"></s:textfield>  改为:

在action里添加get和set方法。

 

3.命名空间(namespace):

警告: Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]

 

可以将包中的action配置国不同的名称空间,这样在不同的名称空间中可以使用同名的action.

Struts2使用action的名字和它所在的名称空间来标识一个action.

默认的名称空间用空字符串("")表示。

 

<package name="login" extends="struts-default" namespace="/loginns">
  <action name="login" >

 

如果请求/loginns/login.action

 

4.为啥传入的字符struts2并没有转换成boolean成功? 传入"1"也是false?

<s:radio name="user.manager"  list="#{true:'是',false:'否'}" label="是否管理员"></s:radio>

传入的字符串如果不是"true",都是false.

 

5.传递中文出现乱码?

<result type="redirectAction">${nextAction}?name=${user.name}</result>

 

解决方法:在传递name之前先编码:user.setName(java.net.URLEncoder.encode(name,"UTF-8"));

 

6.警告: Could not find action or result
There is no Action mapped for namespace /loginns and action name manager?name=大小. - [unknown location]??

 

 

7.Struts2中namespace的用法??

<s:form action="login" namespace="/freem">   action里login不需要加后缀.action

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics