简体   繁体   English

编译错误:包javax.servlet.jsp不存在

[英]Compile error: package javax.servlet.jsp does not exist

first of all, this is not a duplicated post, since: 首先,这不是重复的帖子,因为:

1.- I'm building without any IDE, Ant nor Maven. 1.-我在构建时没有任何IDE,Ant或Maven。

2.- I've already looked for it, and tried the solutions given in: Compile error: package javax.servlet does not exist . 2.-我已经在寻找它,并尝试了以下解决方案: 编译错误:包javax.servlet不存在

However, my problem is still here. 但是,我的问题仍然存在。

Basically, I'm trying to import: 基本上,我正在尝试导入:

import javax.servlet.jsp.JspWriter;

But at compiling time I get: 但是在编译时我得到:

./src/tfg/lti/UI/Painter.java:4: error: package javax.servlet.jsp does not exist import javax.servlet.jsp.JspWriter

I was compiling the class like the first of next lines, and after looking for solutions, I tried the next ones, since an user said that the link files gave him troubles and needed to point to the real file: 我像下一行的第一行一样编译类,在寻找解决方案之后,我尝试了下一个,因为用户说链接文件给他带来了麻烦,需要指向实际文件:

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/ ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/tomcat6/lib/servlet-api.jar ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api.jar ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api-2.5.jar ./src/tfg/lti/Config/Setup.java

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api-2.4.jar ./src/tfg/lti/Config/Setup.java

As You can see, I tried with all the posibble link to the files I've for the package, but I still obtain the error when compiling. 如您所见,我尝试使用所有指向该软件包的文件的Posibble链接,但在编译时仍会收到错误消息。 There You can see the files in a quick view: 在那里您可以快速查看文件:

ll /usr/share/tomcat6/lib/ | grep servlet
lrwxrwxrwx 1 root root   30 jul 24  2014 servlet-api.jar -> ../../java/servlet-api-2.5.jar

ll /usr/share/java/ | grep servlet
-rw-r--r--   1 root root    93251 oct 22  2011 servlet-api-2.4.jar
-rw-r--r--   1 root root    88360 jul 24  2014 servlet-api-2.5.jar
lrwxrwxrwx   1 root root       19 oct 22  2011 servlet-api.jar -> servlet-api-2.4.jar

Any idea about it? 有什么想法吗?

Thank you in advance 先感谢您

Update : Since Albert told me to use jsp-api in classpath, I tried the following ones: 更新 :由于Albert告诉我在类路径中使用jsp-api,因此我尝试了以下方法:

javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/tomcat6/lib/servlet-api.jar:/usr/share/tomcat6/lib/jsp-api.jar ./src/tfg/lti/Config/Setup.java
javac -Xlint -d ./Server/WEB-INF/classes/ -cp ./Server/WEB-INF/classes/:./Server/WEB-INF/jar/:/usr/share/java/servlet-api-2.4.jar:/usr/share/java/jsp-api-2.1.jar ./src/tfg/lti/Config/Setup.java

With the same results. 具有相同的结果。 The files jsp-api that are available for me: 可供我使用的文件jsp-api:

ll /usr/share/tomcat6/lib/ | grep jsp-api
lrwxrwxrwx 1 root root   26 jul 24  2014 jsp-api.jar -> ../../java/jsp-api-2.1.jar

Update 2 : Adding what jsp-api.jar contains (you're right Albert, JspWriter is inside it). 更新2 :添加jsp-api.jar包含的内容(您是对的Albert,它里面包含JspWriter)。 Adding some code (imports and something more). 添加一些代码(导入等)。

jsp-api-2.1.jar content: jsp-api-2.1.jar内容: jsp-api-2.1.jar内容

Code from the class that is giving the faulire: 来自该类的代码提供了有趣的内容:

Imports: 进口:

import java.util.Date;
import javax.servlet.jsp.JspWriter;
import java.io.IOException;
import tfg.lti.Config.TextFileWorker;

First function, which calls the function where JspWriter is used: 第一个函数,它调用使用JspWriter的函数:

public void BuildUI(boolean periodEnabled, Date nextDeliver, 
        String nextDeliveryTitle, String path, JspWriter webWriter)

Call for the function: 调用该函数:

BuildLoadUI(nextDeliveryTitle, path, webWriter);

Part of the target function which I need to work: 我需要工作的部分目标功能:

private void BuildLoadUI(String nextDeliveryTitle, String path,
                                JspWriter webWriter) throws IOException
{

    TextFileWorker Reader = new TextFileWorker();
    String[] fileString;

    webWriter.print("<h2>Evaluación - " + nextDeliveryTitle + "</h2>" + '\n');

我认为您错过了在classpath添加lib/jsp-api.jar位置。

if you are using maven, add this in: 如果您使用的是maven,请在以下位置添加:

<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
</dependency>

where version should match yours in repository 版本应与存储库中的版本匹配

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM