Struts The absolute uri: http://struts.apache.org/

2020-05-03 01:10发布

Using Servlet 3.0, Maven 4.0, JDK 8 with compliance 1.8. I don't know if the problem is due to eclipse not being able to build the project against the libraries correctly, or if it's tomcat. It may be a permission issue, despite the fact that i'm running both tomcat and eclipse as root, but who knows. At this point i'm starting to run out of ideas.

Libs Imported

The index.jsp

    <%@ page language="java" %>
<%@ 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" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type">
<title>Page d'Acceuil</title>
</head>
<body>
    <html:form action="/ajouter">
        <table border="1">
            <caption>Gestion des etudiants STRUTS 1</caption>
            <tr>
                <td>Nom:<input type="text" name="nom"/></td>
                <td>Prenom:<input type="text" name="prenom"/></td>
                <td>Cin:<input type="text" name="cin" /></td>
            </tr>
        <tr>
            <td><input type="submit" value="Recherche Etudiant" onclick="recherche()"/></td>
            <td><input type="submit" value="Ajouter Etudiant" onclick="ajout()"/></td>
            <td><input type="submit" value="Supprimer Etudiant" onclick="sup()"/></td>
        </tr>
    </table>
    </html:form>
</body>
        <script type="text/javascript">
            function ajout(){
                this.document.forms[0].action="ajouter.do";
                this.document.forms[0].submit();
            }
            function recherche(){
                this.document.forms[0].action="rechercher.do";
                this.document.forms[0].submit();
            }
            function sup(){
                this.document.forms[0].action="supprimer.do";
                this.document.forms[0].submit();
            }
        </script>
</html>

My index.jsp requests leads to either this error :

    Type Exception Report

Message The absolute uri: http://struts.apache.org/tags-bean cannot be resolved in either web.xml or the jar files deployed with this application

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

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
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:277)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:75)
    org.apache.jasper.compiler.TagLibraryInfoImpl.generateTldResourcePath(TagLibraryInfoImpl.java:250)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:125)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:421)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:479)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1435)
    org.apache.jasper.compiler.Parser.parse(Parser.java:139)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:227)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:201)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:358)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:338)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:325)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:580)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Or this one :

    Type Exception Report

Message java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:176)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Root Cause

java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
    java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:131)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:62)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:171)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Note The full stack trace of the root cause is available in the server logs.

My web.xml is as following, as you can see even if i supposedly shouldn't be adding these taglibs in there since i'm using servlet 3.0, i'm still declaring them just in case.

    <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Etudiant</display-name>

  <!-- Servlet controleur de Struts -->
  <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>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- Mapping des url avec la servlet -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <!-- page d'accueil de l'application -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <jsp-config>
  <taglib>
     <taglib-uri>
      http://struts.apache.org/tags-bean
     </taglib-uri>
     <taglib-location>
      /WEB-INF/struts-bean.tld
     </taglib-location>
</taglib>
<taglib>
     <taglib-uri>
      http://struts.apache.org/tags-html
     </taglib-uri>
     <taglib-location>
      /WEB-INF/struts-html.tld
     </taglib-location>
</taglib>
<taglib>
     <taglib-uri>
      http://struts.apache.org/tags-logic
     </taglib-uri>
     <taglib-location>
      /WEB-INF/struts-logic.tld
     </taglib-location>
</taglib>
  </jsp-config>
</web-app>

My deployment assembly and java build path are also updated correctly to include those libs, but none of this seems to solution the problem.

If you have any idea, i would gladly look into it.

1条回答
▲ chillily
2楼-- · 2020-05-03 01:52

SOLUTION :

I've managed to resolve this problem by following these steps :

1) Remove all the tlds. and struts jars from lib.

2) Convert the project to maven nature

3) Have the following dependencies added to the pom.xml

 <dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts-core -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts-core</artifactId>
        <version>1.3.10</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts-taglib -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts-taglib</artifactId>
        <version>1.3.10</version>
    </dependency>
</dependencies>

4) Use the corresponding struts configuration dtd in struts-config header, for me it was the following since i was using Struts 1.3 :

    <!DOCTYPE struts-config PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
   "http://struts.apache.org/dtds/struts-config_1_3.dtd">

5) Make sure the action(s) bracket(s) syntax is correct :

<action path="/ajouter" input="/index.jsp" name="myFormBean"
         type="org.your.pckg.src.MyServletAction">
            <forward name="success" path="/redirection_page.jsp" />
        </action>

And that's pretty much it, you may also have to change your java compliance as i had to downgrade from 1.8 to 1.7 to make it work.

Ultimately this doesn't answer the question why the previous error pages were showing up despite the fact that all libraries were seemingly well imported and declared, i suspect the root of the problem to be lying in a compatibility issue between either tomcat or eclipse and the struts jars used, preventing the compiler from accessing the tld files and reading them. At any rate what seems to appear clear through this is the inability of the server to deploy the tlds, the reason of this has yet to be defined.

查看更多
登录 后发表回答