“Import cannot be resolved” with JSP

白昼怎懂夜的黑 提交于 2019-12-05 04:13:53

you should give fully qualified name for your class. (packagename.classname) like:

    <%@ page import="pkgname.Class1"%>

Page directives are normally placed at the top of a JSP. Also I assume Class1 is in the default package since it does not possess a fully qualified name. If Class1 is in a package you need to prefix the name in the import with the package name.

<%@ page import="java.util.*" %>
<%@ page import="Class1" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
</head>
<body>
    <p>
<%
Class1 tc=new Class1("test");
out.print(tc.str);
  %>
    </p>
</body>
Sai Surya

First of all, /WEB-INF/src is the wrong place to keep your java sources (since WEB-INF folder contents are deployed to your server); you should want to move them out of /WEB-INF (into /src in project root, for example)

Either way, you need to tell Eclipse where your sources are and where you want classes built to. It's done in project properties dialog:

  1. Right-click on your project in Eclipse, select Properties

  2. Click on Java Build path on the left

  3. Click source tab on the right

  4. Click Add Folder button and add your source folder (/WEB-INF/src or wherever you moved it to)

  5. Ensure Allow output folders for source folders is checked below

  6. Under newly added source path select output folder and point it to /WEB-INF/classes or other location of your choice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!