在编写jsp页面是,导入需要的包,运行时报错
main.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.beans.Employee" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>员工管理系统</h3>
<a href="add.jsp">添加员工信息</a>
姓名:<input type="text" name="naem">
<input type="submit" value="查找">
<form>
<table border="1px">
<tr><td>雇员号</td><td>姓名</td><td>出生日期</td><td>薪水</td><td>编辑</td><td>删除</td></tr>
<%
List<Employee> list = (List<Employee>)session.getAttribute("list");
for(Employee employee : list){
%>
<tr>
<td><%=employee.getId() %></td>
<td><%=employee.getName() %></td>
<td><%=employee.getBirthday() %></td>
<td><%=employee.getSalary() %></td>
<td><a href="#">编辑</a></td>
<td><a href="#">删除</a></td>
</tr>
<%
}
%>
</table>
</form>
</body>
</html>
运行后报错
当将<%@ page import="com.beans.Employee" %>改为<%@ page import="com.beans.*" %>后下面的错误消失了
在生成的java文件中的第:[15]行发生错误:[D:\Documents\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\employee\org\apache\jsp\main_jsp.java]
Only a type can be imported. com.beans.Employee resolves to a package
但是
Employee cannot be resolved to a type
依旧存在
疑似原因:
jsp容器先将jsp文件转换成一个java源文件(java servlet源文件),在把java源文件编译成字节码文件(以.class结尾)
运行时项目没有自动编译
解决方法:
1、在Project里勾选Build Automatically然后运行项目
2、如果1不行,点击Project里的Clean,选择当前项目,点击Clean,再次运行项目