Struts2中debug标签页面无法显示解决办法

本文详细介绍了在Struts2框架中使用debug标签的方法,解释了为何页面中可能不显示debug标签创建的链接,并提供了开启debug模式的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天,在写代码时,使用struts2中的debug标签输出一下信息,但是在使用过程中发现页面中无法显示debug标签自动创建的链接。

先说解决办法:  配置struts默认常量中的struts.devMode 值为 true 就可以解决 

下面说一下原因:

特意写了个例子:  页面运行是访问DebugAction 进入到execute方法 输出“DebugAction” 然后返回SUCCESS,跳转到show.jsp 在show.jsp页面写了<debug></debug>标签 代码如下:

这是action类(为了演示,只输出了一句话,然后跳转。)

package com.study.action;

import com.opensymphony.xwork2.ActionSupport;

public class DeBugAction extends ActionSupport{

	@Override
	public String execute() throws Exception {
		System.out.println("DebugAction");
		return SUCCESS;
	}
	
}

struts.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<package name="Debug" namespace="/" extends="struts-default">
		<action name="DebugAction" class="com.study.action.DeBugAction" method="execute">
			<result name="success">/show.jsp</result>
		</action>
	</package>
</struts>

web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>13OGNL表达式</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <filter>
  	<filter-name>struts</filter-name>
  	<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
  	<filter-name>struts</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

show.jsp 页面:

<%@ page  pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<title>13ONGLdebug</title>
</head>
<body>
 <s:debug></s:debug>
</body>
</html>

运行结果:

可见Action中的execute方法已经被执行,但是页面没有链接。  

接下来我们看一下当前页面的源码和我们写的jsp源码对比:(eclipse自带浏览器右键查看源会弹出一个记事本)

这里我们发现<debug></debug>标签压根没有被编译 于是,我们看一下这个标签的tld  在jsp源码上按住ctrl,点击我们配置的taglib中的uri=“/struts-tags”  跳转到tld页面 

在这个页面我们直接ctrl + f 搜索debug 可以看到下面这个描述:

我们看到这句描述的意思是说输出debug信息 (只有在struts.devMode 被激活)也就是说,我们必须开启struts的debug模式才可以,下面我们在struts.xml配置一下:

<constant name="struts.devMode" value="true"></constant>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<constant name="struts.devMode" value="true"></constant>
	<package name="Debug" namespace="/" extends="struts-default">
		<action name="DebugAction" class="com.study.action.DeBugAction" method="execute">
			<result name="success">/show.jsp</result>
		</action>
	</package>
</struts>

然后重启服务器  访问一下试试:

  

然后我们点击一下看看内容:

问题解决。  欢迎交流

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值