나는 학교용 온라인 텍스트 편집기를 쓰고 있습니다. 사용자 정의 이름으로 파일을 저장할 수 있었으므로 문제는 아닙니다. 내가 가지고있는 HTML 폼을 가지고 TextArea의 텍스트를 사용자가 지정한 파일에 제출하고 url을 blah.org/text.jsp?status=gen으로 설정합니다. 나중에 코드에서 변수 상태 == gen이면 프로그램에 파일을 쓰게하고 그렇지 않으면 아무것도하지 않습니다. 제출을 클릭하면 파일을 만들 수 없으며 URL에 변수를 가져 오는 것과 관련이 있다고 생각합니다.JSP로 URL 변수를 가져 오지 못했습니다.
/* Set the "user" variable to the "user" attribute assigned to the session */
String user = (String)session.getAttribute("user");
String status = request.getParameter("status");
/* Get the name of the file */
String name = request.getParameter("name");
/* Set the path of the file */
String path = "C:/userFiles/" + user + "/" + name + ".txt";
/* Get the text in a TextArea */
String value = request.getParameter("textArea");
/* If there isn't a session, tell the user to Register/Log In */
if (null == session.getAttribute("user")) {
out.println("Please Register/Log-In to continue!");
if (status == "gen") {
try {
FileOutputStream fos = new FileOutputStream(path);
PrintWriter pw = new PrintWriter(fos);
pw.println(value);
pw.close();
fos.close();
}
catch (Exception e) {
out.println("<p>Exception Caught!");
}
} else {
out.println("Error");
}
}
양식 : 여기 내 코드입니다
<form name="form1" method="POST" action="text.jsp?status=gen">
<textarea cols="50" rows="30" name="textArea"></textarea>
<center>Name: <input type="text" name="name" value="Don't put a .ext"> <input type="submit" value="Save" class="button"></center>
other code here </form>