日期:2014-05-17  浏览次数:20715 次

使用struts 出现不能解析标签库
开发环境:myeclipse7.5 struts1.3 tomcat5.5 不知怎么添加本地图片,我就直接复制代码

这是JSP页面使用的标签库:
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

以下是web.xml页面的配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>

出现此异常:
org.apache.jasper.JasperException: The absolute uri: http://struts.apache.org/tags-bean cannot be resolved in either web.xml or the jar files deployed with this application

个人困惑:在myeclipse中使用strust自带的标签库应该不需要配置的吧,我看视频也没有配置。



------解决方案--------------------
还有人用struts1啊!
这样,你吧.tld文件放到你工程的WEB-INF目录下,再把uri改成:/WEB-INF/struts-logic.tld,也就是tld文件的相对路径!试试吧!

其实struts的标签不好使,不如自己写一个,下面演示一下自定义标签的使用,就用输出网站完整url为例:
Java code

package zl.framework.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

/**
 * 输出项目完整路径(带协议的)
 * @version 2.0
 */
public class RootPathTag extends BaseTag {

    private static final long serialVersionUID = 1L;

    public int doStartTag() throws JspException {
        HttpServletRequest request = getRequest();
        String rootPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
        write(rootPath);
        return SKIP_BODY;
    }

}