初学spring遇到的问题
刚刚学习spring遇到问题。
(一)applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!--
- Application context definition for "example" DispatcherServlet.
- Heavily depended on web infrastructure, naturally.
-->
<beans>
<bean id="fru" name="com.hyjk.Apple"></bean>
</beans>
(二)测试页面如下 :
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="com.hyjk.*" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试Spring页面</title>
</head>
<body>
<%
ApplicationContext context=null;
context=new ClassPathXmlApplicationContext("applicationContext.xml");
Fruit f=(Fruit)context.getBean("fru");
f.eat();
%>
</body>
</html>
(三)
package com.hyjk;
public class Apple implements Fruit {
@Override
public void eat() {
// TODO Auto-generated method stub
System.out.println("苹果");
}
}
在IE中输入 :http://localhost:8080/TestProject/meter/test.jsp
错误如下:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 7 in the generated java file
Only a type can be imported. org.springframework.context.ApplicationContext resolves to a package
An error occurred at line: 8 in the generated java file
Only a type can be imported. org.springframework.context.support.ClassPathXmlApplicationContext resolves to a package
An error occurred at line: 14 in the jsp file: /meter/test.jsp
ApplicationContext cannot be resolved to a type
11: </head>
12: <body>
13: <%
14: ApplicationContext context=null;
15: context=new ClassPathXmlApplicationContext("applicationContext.xml");
16: Fruit f=(Fruit)context.getBean("fru");
17: f.eat();
An error occurred at line: 15 in the jsp file: /meter/test.jsp
ClassPathXmlApplicationContext cannot be resolved to a type
12: <body>
13: <%
14: ApplicationContext context=null;
15: context=new ClassPathXmlApplicationContext("applicationContext.xml");
16: Fruit f=(Fruit)context.getBean("fru");
17: f.eat();
18: %>
请问该如何修改?