structs的怪异问题

04-11-03 mrglad

小弟遇到一个奇怪的问题。

用JB9建了一个webapplication,创建一个基于structs的应用。
包括creatItem.jsp,viewer.jsp,(三个bean,javabean,action,form都是正确的,没错)
用jb启动报错,"viewer.jsp": org.apache.jasper.compiler.ParseException: End of content reached while more parsing required: tag nesting error?
说是标签未找到???。。。。
struts-bean.tld,struts-html.tld,struts-logic.tld,struts-template.tld这几个模版文件及两个配置文件struts-config.xml均在
web-inf下,没有改动(jb自动生成)。且路径,环境变量均正确。
不解中,把它拷至tomcat5默认目录下,启动tomcat(不是jb自带)用ie察看。不管是creatItem.jsp,viewer.jsp都报一样的错误:
exception 

org.apache.jasper.JasperException: File "/WEB-INF/struts-html.tld" not found
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:404)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:154)
	org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:202)
	org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:460)
	org.apache.jasper.compiler.Parser.parseDirective(Parser.java:525)
	org.apache.jasper.compiler.Parser.parseElements(Parser.java:1625)
	org.apache.jasper.compiler.Parser.parse(Parser.java:173)
	org.apache.jasper.compiler.ParserController.parse(ParserController.java:247)
	org.apache.jasper.compiler.ParserController.parse(ParserController.java:149)
	org.apache.jasper.compiler.ParserController.parse(ParserController.java:135)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:243)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:285)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:232)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


直接用ie察看struts-html.tld,抱错:

DTD 中不支持使用默认的名称空间声明属性。处理资源 'http://localhost:8080/webCart/cart/WEB-INF/struts-html.tld' 时出错。第 10 行,位置: 9 
<taglib>

不解。。。。请高手们帮帮忙,晕死了。是不是jb自带structs的问题?

附源码如下:
creatItem.jsp:
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=GBK" %>
<html:html locale="true">
<head>
<html:base/>
<title>
createTest
</title>
</head>
<body>
<h1>Struts JSP for ActionForm webcart.ItemForm</h1>
<html:errors/>
<html:form action="/itemAction.do" method="POST">

available:<html:text property="item.available"/>
description:<html:text property="item.description"/>
itemId:<html:text property="item.itemId"/>
price:<html:text property="item.price"/>
producer:<html:text property="item.producer"/>

<html:submit property="submit" value="Submit"/><br>
<html:reset value ="Reset"/>
</html:form>
</body>
</html:html>

viewer.jsp
%@ page contentType="text/html; charset=GBK"%>
<%@ page import="webcart.ItemForm"%>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
Test
</title>
</head>
<body>
<%
ItemForm iform=(ItemForm)request.getAttribte("Item");
%>
itemCreated:
available:<%=iform.getAvailable()%><br>
description:<%=iform.getDescription()%><br>
itemId:<%=iform.getItemId()%><br>
price:<%=iform.getPrice()%><br>
producer:<%=iform.getProducer()%><br>
</body>
</html>


struts-html.tld:(前面部分)
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>html</shortname>
<uri>http://jakarta.apache.org/struts/tags-html-1.0.2</uri>
<tag>
<name>base</name>
<tagclass>org.apache.struts.taglib.html.BaseTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>target</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
  </taglib>
</web-app>


struts-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
  <form-beans>
    <form-bean name="itemForm" type="webcart.ItemForm" />
  </form-beans>
  <global-forward>
	<forward name="itemCreated" path="/viewer.jsp"/>
  </global-forward>
  <action-mappings>
    <action name="itemForm" type="webcart.ItemAction" scope="session" path="/itemAction" input="/createItem.jsp" />
  </action-mappings>
</struts-config>

<p>

tyeoon
2004-11-05 10:28
以前遇到过这样的问题,我的原因是jsp上有的标签没有封闭,没有细看你的源码,这也可能只是原因之一,见谅

wildfox
2004-11-09 15:42
jb自动生成的web-inf是大写还是小写? 没有用过,不清楚看你写出来的是小写 如果真是这样 可能是因为这个原因

Hephaestus
2005-01-28 15:06
<html:form action="/itemAction.do" method="POST">available:<html:text property="item.available"/>description:<html:text property="item.description"/>itemId:<html:text property="item.itemId"/>price:<html:text property="item.price"/>producer:<html:text property="item.producer"/><html:submit property="submit" value="Submit"/><br><html:reset value ="Reset"/></html:form>

把<html;form> </html:form>这对标签改为<form> </from>试试。

猜你喜欢