很奇怪,我的Eclipse中怎么不能import 进和Servlet 有关的类呀?
在import 语句前面有红叉,提示不能导入javax.servlet,但是一般的java.开头的包又可以导入,如java.io.IOException,请指教!
谢谢,
我的Eclipse是配置了j2re1.4.2_07的,应该没有问题.
代码如下:
package family.yin.senqi;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Date;
import java.util.Calendar;
import family.yin.senqi.dao.MyDAO;
import family.yin.senqi.model.ModelFour;
import java.sql.*;
/**
* <p> Title: </p>
* <p> Description: </p>
* <p> Copyright: Copyright (c) 2006 </p>
* <p> Company: </p>
* @author not attributable
* @version 1.0
*/
public class BalanceServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
HttpSession session = req.getSession();
Calendar c = Calendar.getInstance();
int nYear = c.get(1);
int nMonth = c.MONTH+1;
String nYear_str = req.getParameter( "nYear ");
String nMonth_str = req.getParameter( "nMonth ");
if(nMonth_str!=null && nYear_str!=null){
nMonth = new Integer(nMonth_str).intValue();
}
MyDAO dao = new MyDAO();
try {
ModelFour[] mf = dao.getBalance(nYear, nMonth);
session.setAttribute( "mf ",mf);
float mTotal = dao.getMonthTotalMoney(nMonth);
session.setAttribute( "mTotal ",new Float(mTotal));
}
catch (SQLException ex) {
ex.printStackTrace();
}
resp.sendRedirect( "balance.jsp?nYear= "+nYear+ "&nMonth= "+nMonth);
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
this.doPost(req,resp);
}
}
------解决方案--------------------
找不到servlet的jar文件了。
------解决方案--------------------
在你的工程中加入j2ee.jar库文件(可以从应用服务器的目录中去找)就可以了
------解决方案--------------------