project_privateとりあえず「非公開ならprivate、外部から読めてもいいならpublic_read」と覚えておくとよいでしょう。
private
public_read
public_read_write
authenticated_read
bucket_owner_read
bucket-owner_full_control
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※helo.jsp <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="java.util.ArrayList" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Sample jsp</title> <style> h1{ font-size: 16pt; background: #AAFFAA; padding: 5px; } table tr td { background: #DDFFDD; padding: 2px; } pre { background: #EEFFFF; padding: 5px; } </style> </head> <body> <h1>Hello App Engine!</h1> <hr> <pre id="msg"><jsp:include page="/mygaeapp"/></pre> <hr> <form method="post" action="/mygaeapp"> <table> <tr> <td>タイトル</td> <td><input type="text" id="title" name="title" size="40"></td> </tr> <tr> <td>コンテンツ</td> <td><textarea id="content" name="content" cols="40" rows="5"></textarea></td> </tr> <tr> <td></td> <td> <input type="submit" value="送信する"> </td> </tr> </table> </form> <hr> </body> </html> ※MyGaeAppServletクラス package com.tuyano.libro.mygaeapp; import java.io.*; import java.nio.channels.Channels; import javax.servlet.http.*; import com.google.appengine.api.files.*; import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder; @SuppressWarnings("serial") public class MyGaeAppServlet extends HttpServlet { public static final String BUCKETNAME = "my_cloud_data"; // バケット名 public static final String FILENAME = "sample.txt"; // ファイル名 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/plain"); request.setCharacterEncoding("utf8"); response.setCharacterEncoding("utf8"); PrintWriter out = response.getWriter(); String filename = "/gs/" + BUCKETNAME + "/" + FILENAME; FileService fileService = FileServiceFactory.getFileService(); AppEngineFile readableFile = new AppEngineFile(filename); FileReadChannel readChannel = null; try { readChannel = fileService.openReadChannel( readableFile, true); BufferedReader reader = new BufferedReader( Channels.newReader(readChannel, "UTF8")); String line = null; while((line = reader.readLine()) != null){ out.println(line); } } catch(FileNotFoundException e){ out.println("no file..."); } finally { try { readChannel.close(); } catch(Exception ex){} } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/plain"); request.setCharacterEncoding("utf8"); response.setCharacterEncoding("utf8"); String title = request.getParameter("title"); String content = request.getParameter("content"); FileService fileService = FileServiceFactory.getFileService(); GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder() .setBucket(BUCKETNAME) .setKey(FILENAME) .setMimeType("text/html") .setAcl("public_read"); AppEngineFile file = fileService .createNewGSFile(optionsBuilder.build()); FileWriteChannel writeChannel = fileService.openWriteChannel(file, true); PrintWriter ch_out = new PrintWriter(Channels .newWriter(writeChannel, "UTF8")); ch_out.println(title); ch_out.println(); ch_out.println(content); ch_out.close(); writeChannel.closeFinally(); response.sendRedirect("/helo.jsp"); } }
<< 前へ | 次へ >> |