[英]Eclipse project window shows error but code editor shows no error
For my jsp file, the code editor shows no error, but the projects window shows an error. 对于我的jsp文件,代码编辑器没有显示错误,但是“项目”窗口显示了错误。 I built my project again, cleaned the project, restart eclipse twice and summoned cthulhu.
我再次构建了项目,清理了该项目,重新启动了eclipse两次并召唤了cthulhu。 But my project still shows an error.
但是我的项目仍然显示错误。 How do I find the cause and fix the problem ?
如何找到原因并解决问题?
Eclipse project - Eclipse项目-
JSP file - JSP文件-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="mine" uri="DiceFunctions"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
${mine:rollIt()}
</body>
</html>
TLD file - TLD文件-
<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.2</tlib-version>
<uri>DiceFunctions</uri>
<function>
<name>rollIt</name>
<function-class>foo.DiceRoller</function-class>
<function-signature>
int rollDice()
</function-signature>
</function>
</taglib>
Note - look at my project structure. 注意-查看我的项目结构。 Make a folder foo under web-inf/classes and put the dice class file inside foo.
在web-inf / classes下创建一个文件夹foo,并将色子类文件放入foo中。 Otherwise the project won't work.
否则,该项目将无法正常工作。
First have you defined taglib
in web.xml as shown below? 首先,您是否在web.xml中定义了
taglib
,如下所示?
<jsp-config> <taglib> <taglib-uri>DiceFunctions</taglib-uri> <taglib-location>/WEB-INF/diceRoller.tld</taglib-location> </taglib> </jsp-config>
Second the lib folder is empty in you project snapshot that means you have not added jstl.jar
in your project. 其次,项目快照中的lib文件夹为空,这意味着您尚未在项目中添加
jstl.jar
。
It should look like 它看起来像
public class DiceRoller {
public int rollDice() {
return 1;
}
}
Find a sample code here on JSP custom tag function example 在JSP自定义标记函数示例上找到示例代码
When I run the html file on tomcat, i get an error - HTTP Status 404 - /MyJSP/html/MyHtml.html
当我在tomcat上运行html文件时,出现错误-HTTP状态404-/MyJSP/html/MyHtml.html
A Web archive (WAR) file is a packaged Web application that can be exported to test, publish, and deploy the resources developed within a Web project. Web存档(WAR)文件是打包的Web应用程序,可以将其导出以测试,发布和部署在Web项目中开发的资源。
To export a WAR file from a Web project, do the following: 要从Web项目中导出WAR文件,请执行以下操作:
Read more about Exporting Web Archive (WAR) files 阅读有关导出Web存档(WAR)文件的更多信息
How I solved the problem - I was lucky that my fluke worked. 我如何解决问题-我很幸运我的fl幸工作成功。 First, copy all the code correctly from the book.
首先,正确复制本书中的所有代码。 Do NOT create any classes folder inside web-inf for your project.
不要在web-inf中为您的项目创建任何类文件夹。 In eclipse jee, create a new dynamic web project.
在eclipse jee中,创建一个新的动态Web项目。 Copy all the folders for jsp, html, java code etc from your old project into the new one.
将旧项目中所有jsp,html,java代码等文件夹复制到新项目中。 Delete your old project.
删除您的旧项目。 Build your new project (try to also close-open eclipse to be safe).
生成您的新项目(为安全起见,也请尝试关闭食)。 Your project should be error free now.
您的项目现在应该没有错误。 I have no explanation for why this worked.
我没有解释为什么这样做。
Alternately , if your goal is to learn J2ee JSP etc. quickly, then I suggest that you avoid using Eclipse initially and make your web app folders manually. 或者 ,如果您的目标是快速学习J2ee JSP等,那么我建议您避免一开始使用Eclipse,而是手动创建Web应用程序文件夹。
Create the following directory structure with all the necessary files: 使用所有必需的文件创建以下目录结构:
C:\APACHE-TOMCAT-7.0.00\WEBAPPS\SAMPLEAPP
¦ MyHtml.html
¦ MyJsp.jsp
¦
+---WEB-INF
¦ DiceRoller.tld
¦ web.xml
¦
+---classes
+---foo
Dice.class
Now put all the necessary code for these files and it will work for sure. 现在,为这些文件放置所有必需的代码,它肯定会起作用。 The moral of this story is that Eclipse is not good to learn the basics of J2EE/Jsp/Servlets.
这个故事的寓意是,Eclipse不适合学习J2EE / Jsp / Servlets的基础知识。 Make your web app folders manually.
手动制作您的Web应用程序文件夹。 I wasted 2-3 hours in trying to make the eclipse version and still failed.
我在尝试制作Eclipse版本时浪费了2-3个小时,但仍然失败了。 I followed the non-eclipse approach and the code was running in 5 minutes.
我遵循了非蚀方法,并且代码在5分钟内运行。 And...there was no need to import any jars or extend any classes etc.
而且...不需要导入任何jar或扩展任何类等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.