eclipseでtomcatを使っています
別のhtmlから文字を受け取ってファイルに出力したいのですがうまくいきません
doPost(HttpServletRequest request, HttpServletResponse r
esponse) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
String body = request.getParameter("body");
body = new String(body.getBytes("8859_1"),"SJIS");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<html><head><title>tt</title></head><body>");
//out.print(body);
try{
String path = getServletContext().getRealPath("/WEB-INF/sample.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(path,true));
bw.write(body);
bw.newLine();
bw.close();
out.print("成功");
}catch(IOException e){
out.print("失敗");
}
out.print("</body></html>");
out.close();
}
}
このように打ったのですが実行してみると??が出ます
成功のところの文字数を増やしたら?の数も増えるので、エラーになってないと思うのですがファイル出力はされません
エラーログも出ていません
解決策を教えてください
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。