servlet----------------------
Questionbank qb=new Questionbank();
qb.setQuestion(request.getParameter("question"));
qb.setOptionA(request.getParameter("optionA"));
qb.setOptionB(request.getParameter("optionB"));
qb.setOptionC(request.getParameter("optionC"));
qb.setOptionD(request.getParameter("optionD"));
qb.setAnswer(request.getParameter("answer").charAt(0));
Part part=request.getPart("image");
if(part.getSize()!=0){
String header = part.getHeader("content-disposition");
String filename=UUID.randomUUID().toString()+"."+this.getExt(header);
qb.setImage(filename);
//保存图片
String storePath = request.getServletContext().getRealPath("/uploadFile");
//把文件写到指定路径
File f=new File(storePath+File.separator);
if(!f.exists()){
f.mkdirs();
}
try{
part.write(storePath+File.separator+filename);
}catch(IOException e){
e.printStackTrace();
}finally{
if(part!=null)
part.delete();
}
}else{
qb.setImage("");
}
qb.setAnalysis(request.getParameter("analysis"));
qbImpl.save(qb);
------------------------------------------------
$("form").ajaxForm({
url:"<%=request.getContextPath()%>/PracticeServlet",
type:"post",
enctype:"multipart/form-data",
iframe:true,
dataType:"text",
success:function(data) {
alert(data);
$("input[type='button'][value='重设']").click();
},
error:function(data) {
alert("出错!");
}
});