📄 ratiocination_let.java
字号:
package main;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import function.*;
public class ratiocination_let extends HttpServlet {
public void doGet (HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException{
request.setCharacterEncoding("UTF-8");
HttpSession httpSession=request.getSession();
String markString=(String)(httpSession.getAttribute("mark"));
response.setContentType("text/html;charset=UTF-8");
PrintWriter outPrintWriter=null;
outPrintWriter=response.getWriter();
if(markString==null||!markString.equals("artificial"))
{
CommonHTML common=new CommonHTML();
outPrintWriter.println(common.GetErrorPageHTML("Invalid Session!"));
}
else{
CommonHTML common=new CommonHTML();
outPrintWriter.println(common.GetFormHTML("ratiocination", "result_let","post", HTMLForGetAllRules(request),""));
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException{
doGet(request, response);
}
private String HTMLForGetAllRules(HttpServletRequest request){
HttpSession session=request.getSession();
StringBuffer HTMLbuffer=new StringBuffer();
String filename=getServletContext().getRealPath("/")+"/WEB-INF/classes/main/Rule.xml";
DataBaseCenter db=new DataBaseCenter(filename);
ArrayList<String> rules=db.GetAllRules();
session.setAttribute("allrules", rules);
int num_of_question=0;
ArrayList<String> ques=new ArrayList<String>();
for(String rule:rules){
String [] temp=rule.split(" ");
int length=temp.length;
for(int j=0;j<length-1;j++){
if(!ques.contains(temp[j])){
ques.add(temp[j]);
num_of_question++;
HTMLbuffer.append(num_of_question+". Is it "+temp[j]+" ?<br>\nYes<input type=\"radio\" name=\"answer"
+num_of_question+"\" value=\"yes\"> No<input type=\"radio\" name=\"answer"+num_of_question+"\"checked=\"true\" value=\"ignore\">" +
"<br><br>\n");
}
}
}
session.setAttribute("num_of_question", String.valueOf(num_of_question));
HTMLbuffer.append("<input type=\"submit\" name=\"submit\" value=\"Submit\" >");
return HTMLbuffer.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -