struts2调试技巧
struts2提供了一个调试信息辅助标签<s:debug/>, 用户开发过程中使用,提供当前action相关的信息供开发人员查看。
当然这也是有前提的,使用此功能的前提是要打开devMode开关。
以下是开启方法,任选其一:
1。 在struts.xml文件中加入的<struts>节点下加入
<constant name="struts.devMode" value="true"/>
2。在struts.properties文件中加入devMode=true
注意:以下均基于devMode模式调试的
下面笔者以一个文件上传讲解struts2的调试技巧
方法一:在任意页面加<s:debug/>标签
当你访问此页面的时候在页面的最下面有一个[Debug]链接,
官方文档Debugging Struts提及到一个browser调试模式,按照官方文档的说明把struts2-config-browser-plugin-x.x.x.x.jar放入lib目录。
笔者访问了debug-browser.action的页面
从访问http://localhost:8080/uploadFile/process.action和http://localhost:8080/uploadFile/process.action?debug=browser
获得视图分析:加了参数后process.action页面的debug标签信息全部消失了。
总结出debug=browser是为了方便开发者了解当前action的对象信息,
与通过Eclipse等ide调试视图方式查看当前action变量信息具有异曲同工之妙。
process.action代码如下:
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="/struts-dojo-tags" prefix="sx"%>
<html>
<head>
<sx:head/>
<head>
<body>
<s:debug/>
</body>
<html>
3 debug=xml(IE、 火狐、Chrome均可用)
访问http://localhost:8080/uploadFile/process.action?debug=xml可获得以xml方式展现的调试信息,具体用途不详。
4 其他调试技巧:
1 struts.xml
<constant name="struts.configuration.xml.reload" value="true"/>
热加载被修改过后的 struts2 配置文件(通常是xml文件)具体用法请查阅网络相关文章
3 tomcat页面编译异常 调试技巧 jsp_precompile=true