I went through the similar questions but the answers doesn't seem to solve the question. I have downloaded this simple project from GitHub https://github.com/PCS0725/blogprabhat to learn java web development. I am using Eclipse for this. I am getting error in the importing java class files. In Eclipse it shows The import java.util cannot be resolved.
<%@page import="main.Config"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.ArrayList"%>
<%@page import="main.datalayer.Database"%>
<%@page import = "main.model.Article" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome Page</title>
<link rel="stylesheet" type="text/css" href="<%=Config.style %>" />
</head>
<body>
<div id="container">
<a href="."><img id="logo2" src="<%=Config.imageSrc %>" alt="My name here"></a>
<ul id="headlines">
<%
ArrayList<Article> articles = Database.getList(Config.numRows); //number of articles to show on homepage
int i = 0;
for(i=0; i<articles.size();++i) //parse all articles and diplay in a format
{
int id = articles.get(i).getId();
Date date = articles.get(i).getPublicationDate();
java.text.SimpleDateFormat sdf =
new java.text.SimpleDateFormat("dd MMMM ");
String dte = sdf.format(date);
//passing a paramter(viewArticleId) to viewArticle.jsp to specify the article
%>
<li>
<h2>
<span class="pubDate"><%=dte %></span><a href="viewArticle.jsp?viewArticleId=<%=id%>"><%=articles.get(i).getTitle()%></a>
</h2>
<p class="summary"><%=articles.get(i).getSummary() %></p>
</li>
<%
}
%>
</ul>
<p><a href="archive.jsp">Article Archive</a></p>
<div id="footer" style = "text-align : center">
<%=Config.footer %><a href="loginForm.jsp">Site Admin</a>
</div>
</div>
</body>
</html>
Error on the Server :
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file: [C:\Users\brijr\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\blogprabhat\org\apache\jsp\index_jsp.java]
Only a type can be imported. main.Config resolves to a package
An error occurred at line: [17] in the generated java file: [C:\Users\brijr\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\blogprabhat\org\apache\jsp\index_jsp.java]
Only a type can be imported. main.datalayer.Database resolves to a package
An error occurred at line: [18] in the generated java file: [C:\Users\brijr\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost\blogprabhat\org\apache\jsp\index_jsp.java]
Only a type can be imported. main.model.Article resolves to a package
i had the same problem i was i importing my class User from a package p1 but i was getting this error :
all i did is change
pageEncoding="ISO-8859-1"topageEncoding="UTF-8"and it worked !Changing the page encoding to UTF-8 might have fixed the problem by ensuring better handling of characters and byte sequences. Sometimes, character encoding issues can cause unexpected errors in code interpretation. Switching to UTF-8 possibly resolved an underlying parsing issue, enabling the class import to function properly.
solution
it worked !