Jetty JSP页面显示导入语句的编译错误

时间:2018-06-29 16:53:34

标签: jsp jetty-9

  

大家好,

     

我只是使用一个示例尝试一个嵌入式Jetty JSP的示例   显示在网站上。

     

主要具有以下依赖性:

     

行家:

     

pom.xml

y=c("ab","c","def","gghh")
  

web.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.eclipse.jetty.demo</groupId>
  <artifactId>embedded-jetty-jsp</artifactId>
  <version>1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jetty-version>9.4.5.v20170502</jetty-version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-annotations</artifactId>
      <version>${jetty-version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-webapp</artifactId>
      <version>${jetty-version}</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>apache-jsp</artifactId>
      <version>${jetty-version}</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>apache-jstl</artifactId>
      <version>${jetty-version}</version>
      <type>pom</type>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <configuration>
          <useManifestOnlyJar>false</useManifestOnlyJar>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <configuration>
          <executable>java</executable>
          <arguments>
            <argument>-Dtomcat.util.scan.StandardJarScanFilter.jarsToScan=taglibs-standard-impl-*</argument>
            <argument>-Dtomcat.util.scan.StandardJarScanFilter.jarsToSkip=apache-*,ecj-*,jetty-*,asm-*,javax.servlet-*,javax.annotation-*,taglibs-standard-spec-*</argument>
            <argument>-cp</argument>
            <classpath />
            <argument>org.eclipse.jetty.demo.Main</argument>
            <argument>8080</argument>
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
  

启动服务器的主程序:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>JSP Example Application</display-name>

    <servlet id="jsp">
        <servlet-name>uu</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>logVerbosityLevel</param-name>
            <param-value>DEBUG</param-value>
        </init-param>
        <init-param>
            <param-name>fork</param-name>
            <param-value>>false</param-value>
        </init-param>
        <init-param>
            <param-name>keepgenerated</param-name>
            <param-value>>true</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
        <url-pattern>*.jspf</url-pattern>
        <url-pattern>*.jspx</url-pattern>
        <url-pattern>*.xsp</url-pattern>
        <url-pattern>*.JSP</url-pattern>
        <url-pattern>*.JSPF</url-pattern>
        <url-pattern>*.JSPX</url-pattern>
        <url-pattern>*.XSP</url-pattern>
    </servlet-mapping>
</web-app>
  

它也有一个jsp页面,我在其中导入了这样的Jetty Server。

     

example.jsp

              Java Code Geeks片段-示例JSP页面                          


当前日期是:<%= new java.util.Date()%>服务器   版本:<%= org.eclipse.jetty.server.Server.getVersion()   %>

     

问题是我无法弄清为什么这个jsp页面在类路径中已经设置后却找不到org.eclipse.jetty.server.Server。

尝试调用此页面时出现以下错误。

package com.javacodegeeks.snippets.enterprise.jettyjsp;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyJspExampleMain {

    public static void main(String[] args) throws Exception {

        // 1. Creating the server on port 8083
        Server server = new Server(8083);

        // 2. Creating the WebAppContext for the created content
        WebAppContext ctx = new WebAppContext();
        ctx.setResourceBase("src/main/webapp");
        ctx.setContextPath("/jetty-jsp-example");

        //3. Including the JSTL jars for the webapp.
        ctx.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*jstl.*\\.jar$");

        //4. Enabling the Annotation based configuration
        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");

        //5. Setting the handler and starting the Server
        server.setHandler(ctx);
        server.start();
        server.join();

    }
}
  

任何建议或帮助将不胜感激。

0 个答案:

没有答案