想实现点击“导入试题”后,实现导入试题功能。已经写好了后台代码,前台jsp怎么样才能调用后台的这个action?
package com.oracle.tna.readexcel;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.oracle.tna.domain.Items;
public class ReadExcel {
public static List<Items> readFile() throws IOException{
List<Items> list = new ArrayList<Items>();
String pathname = “file”+File.separator+”items_info.xlsx”;
File f = new File(pathname);
InputStream is = new FileInputStream(f);
XSSFWorkbook xssfworkbook = new XSSFWorkbook(is);
for(int numSheet = 0 ;numSheet<xssfworkbook.getNumberOfSheets();numSheet++){
XSSFSheet xssfsheet = xssfworkbook.getSheetAt(numSheet);
if (xssfsheet == null) {
continue;
}
for(int rowNum = 1;rowNum<=xssfsheet.getLastRowNum();rowNum++){
XSSFRow xssfrow = xssfsheet.getRow(rowNum);
if(xssfrow!=null){
Items item = new Items();
XSSFCell question = xssfrow.getCell(0);
XSSFCell optionA = xssfrow.getCell(1);
XSSFCell optionB = xssfrow.getCell(2);
XSSFCell optionC = xssfrow.getCell(3);
XSSFCell optionD = xssfrow.getCell(4);
XSSFCell answer = xssfrow.getCell(5);
item.setQuestion(String.valueOf(question.getStringCellValue()));
item.setOptionA(String.valueOf(optionA.getStringCellValue()));
item.setOptionB(String.valueOf(optionB.getStringCellValue()));
item.setOptionC(String.valueOf(optionC.getStringCellValue()));
item.setOptionD(String.valueOf(optionD.getStringCellValue()));
item.setAnswer(String.valueOf(answer.getStringCellValue()));
list.add(item);
}
}
}
return list;
}
}
解决方案
40
当然了啊,本人这就是个例子,具体还要你本人去写