<html>
<body>
<%
request.setCharacterEncoding("gb2312");
String content=request.getParameter("content");
%>
<%
try
{
PrintWriter writer= new PrintWriter(new BufferedWriter(new FileWriter("C:\\Tomcat\\webapps\\jsp\\test\\test.txt",true)));
writer.write(content);
writer.close();
out.println("宸茬粡鎶婂唴瀹瑰啓鍏ュ埌 C:\Tomcat\webapps\jsp\test\test.txt");
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>
<form action="writeFile.jsp" method=post>
<textarea name=content cols=20 rows=5></textarea><br>
<input type=submit value=鎻愪氦>
</form>
</body>
</html>
=============================
閿欒鎻愮ず锛?
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /writeFile.jsp
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
5: request.setCharacterEncoding("gb2312");
6: String content=request.getParameter("content");
7: %>
8: <%
9: try
10: {
11: PrintWriter writer= new PrintWriter(new BufferedWriter(new FileWriter("C:\\Tomcat\\webapps\\jsp\\test\\test.txt",true)));
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
======================================
璇烽珮鎵嬫寚鏁欏晩~
8 涓В鍐虫柟妗?/h2>
#1
浣犺矾寰勬湁闂锛孿t鏄浆绉诲瓧绗?浣犵洰褰曟敼涓€涓嬪氨鍙互,姣斿璇碿:\\test,鎴栬€卌:\abc.鍓嶉潰2涓猏\,鍚庨潰1鏍筡.
#2
鐢ㄨ繖涓被鍚ileOutputStream
#3
#4
sssky,璋㈣阿浣犵殑绛斿锛屼絾鏄繕鏄笉琛岋紝杩樻槸鍑虹幇鍚屾牱鐨勯敊璇彁绀恒€傘€傘€傝€屼笖鎴戜釜浜鸿涓轰綘璇寸殑c:\abc鏄笉鏄篃搴旇鏄痗:\\abc鍛€
gongyali2005锛屼篃璋㈣阿浣犲洖澶嶏紝浣嗕篃杩樻槸涓嶈锛岄敊璇彁绀轰篃鍩烘湰娌″彉銆傘€傘€?
#5
PrintWriter writer= new PrintWriter(new BufferedWriter(new FileWriter("C:\\Tomcat\\webapps\\jsp\\test\\test.txt",true)));
writer.write(content);
writer.close();
out.println("宸茬粡鎶婂唴瀹瑰啓鍏ュ埌 C:\\Tomcat\\webapps\\jsp\\test\\test.txt");
濡傛灉浣犵殑杩欎釜鏂囦欢澶癸紙C:\\Tomcat\\webapps\\jsp\\test\\锛夊瓨鍦紝浠g爜搴旇娌℃湁闂锛庢垜鐓т綘杩欎箞鍐欑殑锛屽彲浠ュ疄鐜板姛鑳?
#6
C:\Tomcat\webapps\jsp\test\test.txt杩欎釜鏂囦欢纭畾瀛樺湪鍚?
#7
C:\Tomcat\webapps\jsp\test\test.txt杩欎釜鏂囦欢纭疄瀛樺湪锛屾€庝箞浼氳繖鏍峰晩锛屼綘閭e彲浠ワ紝鎴戣繖鎬庝箞灏变笉琛屽憿锛燂紒
#8
File newFile = new File("f:\\new.txt");
FileWriter fw = new FileWriter(newFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("hello world!\r\nA\r\nB");
bw.flush();
bw.close();
#9
浣犲厛涓嶈鐢ㄥ甫缂撳瓨鐨勭被.
#1
浣犺矾寰勬湁闂锛孿t鏄浆绉诲瓧绗?浣犵洰褰曟敼涓€涓嬪氨鍙互,姣斿璇碿:\\test,鎴栬€卌:\abc.鍓嶉潰2涓猏\,鍚庨潰1鏍筡.
#2
鐢ㄨ繖涓被鍚ileOutputStream
#3
#4
sssky,璋㈣阿浣犵殑绛斿锛屼絾鏄繕鏄笉琛岋紝杩樻槸鍑虹幇鍚屾牱鐨勯敊璇彁绀恒€傘€傘€傝€屼笖鎴戜釜浜鸿涓轰綘璇寸殑c:\abc鏄笉鏄篃搴旇鏄痗:\\abc鍛€
gongyali2005锛屼篃璋㈣阿浣犲洖澶嶏紝浣嗕篃杩樻槸涓嶈锛岄敊璇彁绀轰篃鍩烘湰娌″彉銆傘€傘€?
gongyali2005锛屼篃璋㈣阿浣犲洖澶嶏紝浣嗕篃杩樻槸涓嶈锛岄敊璇彁绀轰篃鍩烘湰娌″彉銆傘€傘€?
#5
PrintWriter writer= new PrintWriter(new BufferedWriter(new FileWriter("C:\\Tomcat\\webapps\\jsp\\test\\test.txt",true)));
writer.write(content);
writer.close();
out.println("宸茬粡鎶婂唴瀹瑰啓鍏ュ埌 C:\\Tomcat\\webapps\\jsp\\test\\test.txt");
濡傛灉浣犵殑杩欎釜鏂囦欢澶癸紙C:\\Tomcat\\webapps\\jsp\\test\\锛夊瓨鍦紝浠g爜搴旇娌℃湁闂锛庢垜鐓т綘杩欎箞鍐欑殑锛屽彲浠ュ疄鐜板姛鑳?
writer.write(content);
writer.close();
out.println("宸茬粡鎶婂唴瀹瑰啓鍏ュ埌 C:\\Tomcat\\webapps\\jsp\\test\\test.txt");
濡傛灉浣犵殑杩欎釜鏂囦欢澶癸紙C:\\Tomcat\\webapps\\jsp\\test\\锛夊瓨鍦紝浠g爜搴旇娌℃湁闂锛庢垜鐓т綘杩欎箞鍐欑殑锛屽彲浠ュ疄鐜板姛鑳?
#6
C:\Tomcat\webapps\jsp\test\test.txt杩欎釜鏂囦欢纭畾瀛樺湪鍚?
#7
C:\Tomcat\webapps\jsp\test\test.txt杩欎釜鏂囦欢纭疄瀛樺湪锛屾€庝箞浼氳繖鏍峰晩锛屼綘閭e彲浠ワ紝鎴戣繖鎬庝箞灏变笉琛屽憿锛燂紒
#8
File newFile = new File("f:\\new.txt");
FileWriter fw = new FileWriter(newFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("hello world!\r\nA\r\nB");
bw.flush();
bw.close();
FileWriter fw = new FileWriter(newFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("hello world!\r\nA\r\nB");
bw.flush();
bw.close();
#9
浣犲厛涓嶈鐢ㄥ甫缂撳瓨鐨勭被.
#1
浣犺矾寰勬湁闂锛孿t鏄浆绉诲瓧绗?浣犵洰褰曟敼涓€涓嬪氨鍙互,姣斿璇碿:\\test,鎴栬€卌:\abc.鍓嶉潰2涓猏\,鍚庨潰1鏍筡.
#2
鐢ㄨ繖涓被鍚ileOutputStream
#3
#4
sssky,璋㈣阿浣犵殑绛斿锛屼絾鏄繕鏄笉琛岋紝杩樻槸鍑虹幇鍚屾牱鐨勯敊璇彁绀恒€傘€傘€傝€屼笖鎴戜釜浜鸿涓轰綘璇寸殑c:\abc鏄笉鏄篃搴旇鏄痗:\\abc鍛€
gongyali2005锛屼篃璋㈣阿浣犲洖澶嶏紝浣嗕篃杩樻槸涓嶈锛岄敊璇彁绀轰篃鍩烘湰娌″彉銆傘€傘€?
gongyali2005锛屼篃璋㈣阿浣犲洖澶嶏紝浣嗕篃杩樻槸涓嶈锛岄敊璇彁绀轰篃鍩烘湰娌″彉銆傘€傘€?
#5
PrintWriter writer= new PrintWriter(new BufferedWriter(new FileWriter("C:\\Tomcat\\webapps\\jsp\\test\\test.txt",true)));
writer.write(content);
writer.close();
out.println("宸茬粡鎶婂唴瀹瑰啓鍏ュ埌 C:\\Tomcat\\webapps\\jsp\\test\\test.txt");
濡傛灉浣犵殑杩欎釜鏂囦欢澶癸紙C:\\Tomcat\\webapps\\jsp\\test\\锛夊瓨鍦紝浠g爜搴旇娌℃湁闂锛庢垜鐓т綘杩欎箞鍐欑殑锛屽彲浠ュ疄鐜板姛鑳?
writer.write(content);
writer.close();
out.println("宸茬粡鎶婂唴瀹瑰啓鍏ュ埌 C:\\Tomcat\\webapps\\jsp\\test\\test.txt");
濡傛灉浣犵殑杩欎釜鏂囦欢澶癸紙C:\\Tomcat\\webapps\\jsp\\test\\锛夊瓨鍦紝浠g爜搴旇娌℃湁闂锛庢垜鐓т綘杩欎箞鍐欑殑锛屽彲浠ュ疄鐜板姛鑳?
#6
C:\Tomcat\webapps\jsp\test\test.txt杩欎釜鏂囦欢纭畾瀛樺湪鍚?
#7
C:\Tomcat\webapps\jsp\test\test.txt杩欎釜鏂囦欢纭疄瀛樺湪锛屾€庝箞浼氳繖鏍峰晩锛屼綘閭e彲浠ワ紝鎴戣繖鎬庝箞灏变笉琛屽憿锛燂紒
#8
File newFile = new File("f:\\new.txt");
FileWriter fw = new FileWriter(newFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("hello world!\r\nA\r\nB");
bw.flush();
bw.close();
FileWriter fw = new FileWriter(newFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("hello world!\r\nA\r\nB");
bw.flush();
bw.close();
#9
浣犲厛涓嶈鐢ㄥ甫缂撳瓨鐨勭被.