testmodmanservlet.java
来自「培训考试系统代码」· Java 代码 · 共 175 行
JAVA
175 行
package com.huawei.icd30.agt.testman;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.huawei.icd30.agt.util.*;
import com.huawei.icd30.common.db.*;
/**
* <p> 接收修改试题页面提交的请求,修改成功定向到列表页面。</p>
* <p> </p>
* <p> </p>
* @author 龙燕茜
* @version 1.0
*/
public class TestModManServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=gb2312";
//Initialize global variables
public void init() throws ServletException
{
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
request.setCharacterEncoding("gb2312");
response.setContentType(CONTENT_TYPE);
//定义连接的实例
SysDbConn aplcoms = null;
try
{
MultiRequest mr = new MultiRequest(request) ;
//获取参数值
String testId = mr.getParameter("testId");
String testType = mr.getParameter("testType");
String content = OperateUtility.strDelEnterChar(mr.getParameter("content"));
String optType = mr.getParameter("opeType");
String optionRs = mr.getParameter("optionRs");
String option = mr.getParameter("option");
String explain = mr.getParameter("explain");
String degree = mr.getParameter("degree");
String classId = mr.getParameter("classId");
String testMeans = mr.getParameter("testMeans");
String useLevel = mr.getParameter("useLevel");
String referenceTime = mr.getParameter("referenceTime");
String queryTerm = mr.getParameter("queryTerm");
//接收图片文件
File toFile = null ;
BufferedOutputStream os = null;
File imgPath = new File(this.getServletContext().getRealPath("agt"));
String subImgPath = "testman" + File.separatorChar + "images" + File.separatorChar;
HashMap imgNameMap = new HashMap();
LinkedList imgNameList = new LinkedList();
String imgFile = mr.getFullFilename();
long increase = System.currentTimeMillis();
while(imgFile!=null && !imgFile.trim().equals(""))
{
String suffix = imgFile.substring(imgFile.lastIndexOf(".") ,imgFile.length());
String newName = String.valueOf(increase++) + suffix;
toFile = new File(imgPath , subImgPath + newName);
imgNameList.add(imgPath+subImgPath+newName);
//保存图片的名字映射
String imgSaveName = File.separatorChar + "agt" + File.separatorChar
+ subImgPath + newName ;
imgNameMap.put(imgFile.replace('\\' ,'/') ,imgSaveName.replace('\\' ,'/')) ;
toFile.getParentFile().mkdirs();
os = new BufferedOutputStream(
new FileOutputStream(toFile));
mr.upload(os);
os.close();
imgFile = mr.getFullFilename() ; // 下一个文件
}
String newContent = null;
if(!(content==null || content.trim().equals("")))
{
// 替换试题内容中的图像信息
newContent = OperateUtility.convertImgName(content ,imgNameMap);
}
//保存试题到数据库中
//得到一个连接的实例
aplcoms = SysConnPool.getInstance().getAplComs();
//调用存储过程P_Agt_TestItemAdd完成试题的修改
aplcoms.preparedSP();
aplcoms.setString(1,testId);
aplcoms.setString(2,newContent);
aplcoms.setString(3,explain);
aplcoms.setString(4,classId);
aplcoms.setString(5,testType);
aplcoms.setString(6,degree);
aplcoms.setString(7,option);
aplcoms.setString(8,optionRs);
aplcoms.setString(9,testMeans);
aplcoms.setString(10,useLevel);
aplcoms.setString(11,referenceTime);
SysDataSet ds = aplcoms.csCommonSP("P_Agt_TestItemMod");
SysRecord rc = ds.getParamSet();
if(rc!=null&&rc.getInt(0)==0)
{//试题修改成功,定向到列表页面
response.sendRedirect("/QueryTest.do?opeType=" + OperatorFlagCode.TEST_QUERY + queryTerm);
return;
}
else
{//试题修改失败
//删除所保存的图片
if(imgNameList != null)
{
for(int i=0;i<imgNameList.size();i++)
{
new File(((String)imgNameList.get(i))).delete();
}
}
//定向到错误页面
response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.TEST_MODERROR);
return;
}
}
catch (SysDbException aple)
{//捕获CommonService系统异常,定向到出错页面
aple.printStackTrace();
response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.COMMONSERVICE_ERROR);
return;
}
catch(java.sql.SQLException sqle)
{//捕获调用aplcoms异常,定向到出错页面
sqle.printStackTrace();
response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.DATABASE_ERROR);
return;
}
catch(IOException ioe)
{
ioe.printStackTrace();
response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.FILE_EORROR);
return;
}
catch(SecurityException se)
{
se.printStackTrace();
response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.FILE_SECURITY_EORROR);
return;
}
catch(Exception e)
{//捕获未知异常,定向到出错页面
e.printStackTrace();
response.sendRedirect("/agt/public/jsp/ShowError.jsp?errorId=" + ErrorCode.UNKNOW_ERROR);
return;
}
finally
{//关闭连接实例
if(aplcoms != null)
{
aplcoms.close();
}
}
}
//Clean up resources
public void destroy()
{
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?