public class TestpaperAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestpaperDAO dao = new TestpaperDAO();
Testpaper testpaper = new Testpaper();
String id = request.getParameter("testsetId");
Testset testset = (Testset)dao.getSession().load(Testset.class, Long.valueOf(id));
testpaper.setTestset(testset);
Student student = (Student)request.getSession().getAttribute("user");
testpaper.setStudent(student);
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count5 = 0;
List list = new ArrayList();
List alist = new ArrayList();
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements())
{
Answers1 answers1 = new Answers1();
String paramName = (String)paramNames.nextElement();
String str = paramName.substring(0, 7);
//单项选择题页面
if(!paramName.equals("testsetId")&&str.equals("xanswer"))
{
String[] paramValues = request.getParameterValues(paramName);
String[] index = paramName.split("_");
Question1 question1 = (Question1)dao.getSession().load(Question1.class, Long.valueOf(index[1]));
String isRight = "0";
if(question1.getResult().equals(paramValues[0]))
{
count1 += Integer.parseInt(testset.getMark1().toString());
isRight = "1";
}
else
isRight = "0";
answers1.setQid(Long.valueOf(index[1]));
answers1.setType("1");
answers1.setAnswer(paramValues[0]);
answers1.setIsRight(isRight);
alist.add(answers1);
}
//接下来是多项选择题,是非题,填空题,简答题,页面的代码跟上面的差不多,在此不列举了
//String str = paramName.substring(0, 7);
这句话,截取字符串0到7给str有什么用?
//String[] index = paramName.split("_");
为什么要用-分割paramname参数,有什么用
//Question1 question1 = (Question1)dao.getSession().load(Question1.class, Long.valueOf(index[1]));
这句话中参数index[1]里面的值为1表示什么,
//answers1.setQid(Long.valueOf(index[1]));
还有这句话中index[1]));
里面的1又表示什么
------最佳解决方案--------------------------------------------------------
//String str = paramName.substring(0, 7);
这句话,截取字符串0到7给str有什么用?---》》》意思 是前台传进来的paramName 可能 是0_1_2_3_456789
0123456789.substring(0, 7) = 0_1_2_3_
//String[] index = paramName.split("_");
为什么要用-分割paramname参数,有什么用paramName.split("_") =new String[]{"0","1","2","3"};
//Question1 question1 = (Question1)dao.getSession().load(Question1.class, Long.valueOf(index[1]));查出ID 为1的Question1
index[1] = "1"
Long.valueOf("1")= 1L;转换成 Long 数据好存入数据库 对应 BIGDICEMAL 数据
意思 是 from Question1 where id = '1' 查出ID 为1的Question1
这句话中参数index[1]里面的值为1表示什么,
//answers1.setQid(Long.valueOf(index[1]));index[1]