我正在使用一个java servlets类,它将我的输入重定向到一个新表中,同时将它们写入文本文件中。 我已经陷入了将它们写在文本文件上的困境。
我使用以下命令从主页面获取参数:
String nume = request.getParameter("nume");
String prenume = request.getParameter("prenume");
String varsta = request.getParameter("data_nasterii");
String pozitie = request.getParameter("pozitie");
String echipa = request.getParameter("selectechipa");
对于每个“pozitie”,这意味着“玩家的位置”我有不同的参数:
String portar =request.getParameter("putere") + request.getParameter("respingere") + request.getParameter("sut") + request.getParameter("agilitate") +
request.getParameter("forta")+request.getParameter("reactie") + request.getParameter("anticipare");
String fundas = request.getParameter("putere") +request.getParameter("respingere") + request.getParameter("pasa") + request.getParameter("tackling") +
request.getParameter("forta")+ request.getParameter("lovcap") + request.getParameter("decizie");
String mijlocas = request.getParameter("putere") + request.getParameter("pasa") + request.getParameter("sut") + request.getParameter("pasa") +
request.getParameter("forta") + request.getParameter("tricks") + request.getParameter("creativitate");
String atacant = request.getParameter("putere") + request.getParameter("pasa") + request.getParameter("sut") + request.getParameter("pasa") +
request.getParameter("forta") + request.getParameter("tricks")+ request.getParameter("creativitate");
在档案上写作:
try {
//file creation
String strPath = "D:\\Jucator.txt";
File strFile = new File(strPath);
//write file
Writer wrt = new BufferedWriter(new FileWriter(strFile));
wrt.write("Nume: " + nume + "\n" + "Prenume: " + prenume + "\n" + "Varsta: " + varsta + "\n" + "Pozitie: " + pozitie + "\n" + "Echipa: " + echipa);
wrt.close();
}
catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
现在我还在编写特定位置的参数,例如
if (pozitie.equals("portar"))
//write portar attributes
if (pozitie.equals("fundas"))
//write fundas attributes
and so on.
欢迎任何帮助或建议, 感谢
问题已解决