我经历了类似的问题,但答案似乎并没有解决这个问题。我从GitHub https://github.com/PCS0725/blogprabhat下载了这个简单的项目来学习java web开发。我使用Eclipse来完成这个。我在导入java类文件时出错。在Eclipse中,它显示无法解决导入java.util。
<%@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>
字符串
服务器上的错误:
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
型
1条答案
按热度按时间9jyewag01#
我也遇到了同样的问题,我从包p1导入我的类User,但我得到了这个错误:
只能导入类型。p1.用户解析为包
我所做的就是将
pageEncoding="ISO-8859-1"
更改为pageEncoding="UTF-8"
,并且成功了!字符串
将页面编码更改为UTF-8可能已通过确保更好地处理字符和字节序列来修复此问题。有时,字符编码问题可能会导致代码解释中出现意外错误。切换到UTF-8可能解决了底层解析问题,从而使类导入能够正常运行。
solution
it worked !的