org/apache/poi/hssf/usermodel/HSSFWorkbook这个类找不到?

浮云若水 2012-03-16 10:48:26
org.apache.poi.hssf.usermodel.HSSFWorkbook
Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source.




import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import co.jp.nec.controller.common.MulipartFileController;
import co.jp.nec.model.SDA_MA_DaichoTeigi_A;
import co.jp.nec.model.common.SDA_MZ_Message;
import co.jp.nec.serviceImp.CommonService;
import co.jp.nec.serviceImp.SDAA.AlldataacquisitionEquipmentSer;



服务器启动没问题 代码也没报错 当我上传 excel 时 读取excel 数据 报错

excel 能上传 后面报错了
2012/03/16 10:28:03 org.apache.catalina.core.StandardWrapperValve invoke
致命的: サーブレット appServlet のServlet.service()が例外を投げました
java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
at co.jp.nec.controller.SDAA.AllDataAcquisitionEquipmentController.fileUpLoad(AllDataAcquisitionEquipmentController.java:148)
at co.jp.nec.controller.SDAA.AllDataAcquisitionEquipmentController.upload(AllDataAcquisitionEquipmentController.java:206)
at co.jp.nec.controller.SDAA.AllDataAcquisitionEquipmentController.checkReference(AllDataAcquisitionEquipmentController.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
...全文
3416 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhiqy_12 2014-06-06
  • 打赏
  • 举报
回复
引用 6 楼 dryZeng 的回复:
[Quote=引用 5 楼 a276202031 的回复:] 是程序运行 后报错 tomcat 运行不报错 [/Quote] 是tomcat运行程序时报的错嘛,eclipse编译时没报错嘛? 那就是poi.jar包在eclipse里面有,但在tomcat下没有。
同意楼上的说法,建议lz将jar包添加到WEB-INF下的lib中,而不是添加的build path
dryZeng 2012-03-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 a276202031 的回复:]

引用 2 楼 cai5 的回复:
apache POI.jar
这个 包 我已经导入了 关键是类找不到
[/Quote]

如果你程序写出来都没报错,说明eclipse里面是导入成功了。

但tomcat运行报错,说明tomcat的webapps下的工程下的lib里面没有导入成功。
浮云若水 2012-03-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cai5 的回复:]
apache POI.jar
[/Quote]这个 包 我已经导入了 关键是类找不到
五哥 2012-03-16
  • 打赏
  • 举报
回复
apache POI.jar
浮云若水 2012-03-16
  • 打赏
  • 举报
回复
package co.jp.nec.controller.SDAA;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import co.jp.nec.controller.common.MulipartFileController;
import co.jp.nec.model.SDA_MA_DaichoTeigi_A;
import co.jp.nec.model.common.SDA_MZ_Message;
import co.jp.nec.serviceImp.CommonService;
import co.jp.nec.serviceImp.SDAA.AlldataacquisitionEquipmentSer;

@Controller
public class AllDataAcquisitionEquipmentController {

private Log log = LogFactory.getLog(MulipartFileController.class);
private String SDA_BumonCD;

@Autowired
private CommonService commonService;

@Autowired
private AlldataacquisitionEquipmentSer alldataacquisitionEquipmentSer;

@RequestMapping(value = "/addUser")
public String addUser() {

return "SDAG/addUser";
}

/**
* test 跳转
*
* @param request
* @param model
* @return
*/
@RequestMapping(value = "doAddUser", method = RequestMethod.POST)
public String addUserSuccuss(HttpServletRequest request, ModelMap model) {
return "SDAA/GSDAA050";
}

/**
* 点击参照按钮事件处理
*
* @param request
* @param model
* @return
*/
@RequestMapping(value = "checkReference", method = RequestMethod.POST)
public String checkReference(HttpServletRequest request, ModelMap model,
@RequestParam(value = "file") MultipartFile multipartFile) {
ArrayList list = new ArrayList<SDA_MA_DaichoTeigi_A>();
SDA_BumonCD = new String();

System.out.println("this is a test message!");
SDA_MZ_Message message = new SDA_MZ_Message();
String fileAcquisition = request.getParameter("hd3");

File file = new File(fileAcquisition);
System.out.println(file.exists());

System.out.println(fileAcquisition.matches(".*\\.(?i)xls"));
// System.out.println("".length());
if (fileAcquisition == "") {
// message = commonService.getMessageById("COM_W_005");
message.setSDA_Messgae("不能为空!");
// System.out.println(message);
model.put("message", message);

return "SDAA/GSDAA050";
}
if (file.exists() && file.isFile()) {

if (fileAcquisition.matches(".*\\.(?i)xls")
|| fileAcquisition.matches(".*\\.(?i)xlsx")) {

System.out.println(fileAcquisition);

try {
upload(model, request, multipartFile, file);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (SDA_BumonCD == "10") {

list = alldataacquisitionEquipmentSer
.selectSDA_MA_DaichoTeigi_A(SDA_BumonCD);
}
if (SDA_BumonCD == "20") {
list = alldataacquisitionEquipmentSer
.selectSDA_MA_DaichoTeigi_B(SDA_BumonCD);
}
if (SDA_BumonCD == "30") {
list = alldataacquisitionEquipmentSer
.selectSDA_MA_DaichoTeigi_C(SDA_BumonCD);
}
if (SDA_BumonCD == "40") {
list = alldataacquisitionEquipmentSer
.selectSDA_MA_DaichoTeigi_D(SDA_BumonCD);
}
if (SDA_BumonCD == "50") {
list = alldataacquisitionEquipmentSer
.selectSDA_MA_DaichoTeigi_E(SDA_BumonCD);
}
return "SDAA/GSDAA050";

}
}

else {
/** 所选文件类型不匹配! */
// message = commonService.getMessageById("COM_W_005");
message.setSDA_Messgae("该路径不存在!");
model.put("message", message);
return "SDAA/GSDAA050";
}
return "SDAA/GSDAA050";
}

void fileUpLoad(File file, MultipartFile multipartFile) {

List<String[]> list = new ArrayList<String[]>();
try {
InputStream is = multipartFile.getInputStream();
is = new FileInputStream(file);
HSSFWorkbook workbook = new HSSFWorkbook(is);
HSSFSheet sheet = workbook.getSheetAt(0);
int rows = sheet.getLastRowNum() + 1 - sheet.getFirstRowNum();

for (int i = 0; i < rows; i++) {
HSSFRow hssfRow = sheet.getRow(i);
int cols = hssfRow.getLastCellNum() + 1
- hssfRow.getFirstCellNum();
String[] str = new String[cols];

for (int j = 0; j < cols; j++) {

Object col = hssfRow.getCell((short) j);
Object colNext = hssfRow.getCell((short) (j + 1));
if (col != null) {
str[j] = col.toString();

} else {

if (colNext != null) {

Object colValue = "";
colValue.toString();
}
}
list.add(str);
}
}

} catch (Exception e) {
// TODO: handle exception
}

for (int i = 0; i < list.size(); i++) {
String[] str = list.get(i);
for (int j = 0; j < str.length; j++) {

System.out.println(str[j]);
}
}
}

public String upload(ModelMap model, HttpServletRequest request,
MultipartFile multipartFile, File file1) throws Exception {
System.out.println("this is a message!");
log.info(multipartFile.getName());
String uploadName = multipartFile.getOriginalFilename();// 上传文件名
String ctxPath = "D:/upload/";
File file = new File(ctxPath);
if (!file.exists()) {
file.mkdir();
}
File uploadFile = new File(ctxPath + uploadName);
FileCopyUtils.copy(multipartFile.getBytes(), uploadFile);
// multipartFile.transferTo(file);
model.put("emssage", "success!!!");
System.out.println("__________________________________");
fileUpLoad(file1, multipartFile);
return "SDAA/GSDAA050";
}

}
dryZeng 2012-03-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 a276202031 的回复:]
是程序运行 后报错 tomcat 运行不报错
[/Quote]

是tomcat运行程序时报的错嘛,eclipse编译时没报错嘛?

那就是poi.jar包在eclipse里面有,但在tomcat下没有。
浮云若水 2012-03-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dryzeng 的回复:]
引用 3 楼 a276202031 的回复:

引用 2 楼 cai5 的回复:
apache POI.jar
这个 包 我已经导入了 关键是类找不到


如果你程序写出来都没报错,说明eclipse里面是导入成功了。

但tomcat运行报错,说明tomcat的webapps下的工程下的lib里面没有导入成功。
[/Quote]
是程序运行 后报错 tomcat 运行不报错

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧