- 浏览: 2560104 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Google App Engine(3)Java Start and User Service
User service lets your application integrate with Google user accounts.
Using Users
Change the servlet something like following:
publicvoid doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
resp.setContentType("text/plain");
resp.getWriter().println(
"Hello, " + user.getNickname() + ". Your email will be "
+ user.getEmail());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
Eclipse compiles the new code automatically, then attempts to insert the new code into the already-running server. Changes to classes, JSPs static files and app engine-web.xml are reflected immediately in the running server without needing to restart.
Only if I change web.xml or other configuration files, I need to stop and start the server.
When this runs on local machine, the redirect goes to the page where we can enter any email address to simulate an account sign-in.
Using JSPs
We can do output the HTML in servlets, but that would be difficult to maintain as the HTML get complicated.
Hello, JSP
The content of the JSP page will be mostly like I design my old JSP projects in guestbook.jsp under war directory:
<%@pagecontentType="text/html;charset=UTF-8"language="java"%>
<%@pageimport="java.util.List"%>
<%@pageimport="com.google.appengine.api.users.User"%>
<%@pageimport="com.google.appengine.api.users.UserService"%>
<%@pageimport="com.google.appengine.api.users.UserServiceFactory"%>
<%@taglibprefix="fn"uri="http://java.sun.com/jsp/jstl/functions"%>
<html>
<body>
<%
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
pageContext.setAttribute("user", user);
%>
<p>
Hello, ${fn:escapeXml(user.nickname)}! (You can <a
href="<%=userService.createLogoutURL(request.getRequestURI())%>">sign
out ${fn:escapeXml(user.email)}</a>.)
</p>
<%
} else {
%>
<p>
Hello! <a
href="<%=userService.createLoginURL(request.getRequestURI())%>">Sign
in</a> to include your name with greetings you post.
</p>
<%
}
%>
</body>
</html>
I can visit this page for verification:
http://localhost:8888/guestbook.jsp
The Guestbook Form
Add the very simple form in guestbook.jsp
<formaction="/sign"method="post">
<div><textareaname="content"rows="3"cols="60"></textarea></div>
<div><inputtype="submit"value="Post Greeting"/></div>
</form>
A new servlet to handle the post message SignGuestbookServlet.java
Simple, very simple servlet to output some greeting message in console.
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String content = req.getParameter("content");
if (content == null) {
content = "(No greeting)";
}
if (user != null) {
log.info("Greeting posted by user " + user.getNickname() + ": "
+ content);
} else {
log.info("Greeting posted anonymously: " + content);
}
resp.sendRedirect("/guestbook.jsp");
}
Do the mapping according to the sample of GuestbookServlet
The logging configuration file is logging.properties and it is already configured in file app engine-web.xml:
<system-properties>
<propertyname="java.util.logging.config.file"value="WEB-INF/logging.properties"/>
</system-properties>
The default log level is WARNING, which suppresses INFO message.
guestbook.level = INFO, but for me, it should be
com.sillycat.easymymessage.level = INFO
Yes, I verified from this URL http://carl.digby.com:8888/guestbook.jsp. It works.
References:
https://developers.google.com/appengine/docs/java/gettingstarted/usingusers
https://developers.google.com/appengine/docs/java/gettingstarted/usingjsps
User service lets your application integrate with Google user accounts.
Using Users
Change the servlet something like following:
publicvoid doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
resp.setContentType("text/plain");
resp.getWriter().println(
"Hello, " + user.getNickname() + ". Your email will be "
+ user.getEmail());
} else {
resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
}
}
Eclipse compiles the new code automatically, then attempts to insert the new code into the already-running server. Changes to classes, JSPs static files and app engine-web.xml are reflected immediately in the running server without needing to restart.
Only if I change web.xml or other configuration files, I need to stop and start the server.
When this runs on local machine, the redirect goes to the page where we can enter any email address to simulate an account sign-in.
Using JSPs
We can do output the HTML in servlets, but that would be difficult to maintain as the HTML get complicated.
Hello, JSP
The content of the JSP page will be mostly like I design my old JSP projects in guestbook.jsp under war directory:
<%@pagecontentType="text/html;charset=UTF-8"language="java"%>
<%@pageimport="java.util.List"%>
<%@pageimport="com.google.appengine.api.users.User"%>
<%@pageimport="com.google.appengine.api.users.UserService"%>
<%@pageimport="com.google.appengine.api.users.UserServiceFactory"%>
<%@taglibprefix="fn"uri="http://java.sun.com/jsp/jstl/functions"%>
<html>
<body>
<%
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user != null) {
pageContext.setAttribute("user", user);
%>
<p>
Hello, ${fn:escapeXml(user.nickname)}! (You can <a
href="<%=userService.createLogoutURL(request.getRequestURI())%>">sign
out ${fn:escapeXml(user.email)}</a>.)
</p>
<%
} else {
%>
<p>
Hello! <a
href="<%=userService.createLoginURL(request.getRequestURI())%>">Sign
in</a> to include your name with greetings you post.
</p>
<%
}
%>
</body>
</html>
I can visit this page for verification:
http://localhost:8888/guestbook.jsp
The Guestbook Form
Add the very simple form in guestbook.jsp
<formaction="/sign"method="post">
<div><textareaname="content"rows="3"cols="60"></textarea></div>
<div><inputtype="submit"value="Post Greeting"/></div>
</form>
A new servlet to handle the post message SignGuestbookServlet.java
Simple, very simple servlet to output some greeting message in console.
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String content = req.getParameter("content");
if (content == null) {
content = "(No greeting)";
}
if (user != null) {
log.info("Greeting posted by user " + user.getNickname() + ": "
+ content);
} else {
log.info("Greeting posted anonymously: " + content);
}
resp.sendRedirect("/guestbook.jsp");
}
Do the mapping according to the sample of GuestbookServlet
The logging configuration file is logging.properties and it is already configured in file app engine-web.xml:
<system-properties>
<propertyname="java.util.logging.config.file"value="WEB-INF/logging.properties"/>
</system-properties>
The default log level is WARNING, which suppresses INFO message.
guestbook.level = INFO, but for me, it should be
com.sillycat.easymymessage.level = INFO
Yes, I verified from this URL http://carl.digby.com:8888/guestbook.jsp. It works.
References:
https://developers.google.com/appengine/docs/java/gettingstarted/usingusers
https://developers.google.com/appengine/docs/java/gettingstarted/usingjsps
发表评论
-
Stop Update Here
2020-04-28 09:00 322I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 484NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 374Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 375Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 345Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 436Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 444Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 381Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 463VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 394Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 487NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 432Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 342Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 255GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 455GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 332GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 324Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 302Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 315Serverless with NodeJS and Tenc ...
相关推荐
原名: Google App Engine Java and GWT Application Development 作者: Daniel Guermeur, Amy Unruh 资源格式: PDF 版本: 文字版 出版社: Packt Publishing书号: 1849690448发行时间: 2010年 地区: 美国 语言: 英文 ...
Get a feel for app deployment using Docker and Google App Engine Table of Contents Chapter 1: Chat Application with Web Sockets Chapter 2: Adding User Accounts Chapter 3: Three Ways to Implement ...
In this book, you'll learn these new features: how to use module-driven development with Ember CLI, take advantage of the new DOM-based rendering engine, and use a service-based architecture to make ...
You'll start with game design fundamentals and programming basics, and then progress toward creating your own basic game engine and playable game apps that work on Android and earlier version ...
Use the physics engine to apply forces and detect collisions Add sounds and music and change playback properties Integrate your game with Game Center and make In-App purchases Approach This book is an...
Python框架Yate,全称为Yet Another Template Engine,是一个基于模板的Python框架,旨在简化Web应用的开发过程。它利用模板语言将静态内容与动态逻辑分离,使得开发者可以专注于业务逻辑,而设计师则可以专注于页面...
scripts/mysql_install_db --basedir=/app/mysql1/mysql --datadir=/app/mysql1/mysql/data --user=mysql ``` **4. 设置配置文件** 修改默认的配置文件,以便正确配置第一个实例: ```bash cp support-files...
8. 启动MySQL server:执行命令service mysqld start,启动MySQL server。 三、安装Nginx (略) 四、安装Redis (略) 五、安装MinIO (略) 本文档提供了一个详细的Linux环境搭建流程,涵盖了JDK、MySQL、...
python-app-with-electron-gui 为Python应用制作GUI的更好方法 使用HTML,JavaScript和CSS制作高度定制的跨平台桌面应用程序,这些应用程序使用本机Python后端。 注意:这仅出于教育目的,可能不是有效的或没有...
##### 3. 创建`my.ini`配置文件 - 在MySQL安装目录下创建一个名为`my.ini`的文本文件,用于配置MySQL服务器的基本参数。 - 内容示例: ```ini [client] port = 3306 socket = /data/3306/mysql.sock default-...
示例:OpenShift中单个节点上的三层应用程序 此示例显示了如何在OpenShift上部署三层应用... oc new-app --name=mysql5 --docker-image=mysql:5.7 \ -e MYSQL_USER=user1 -e MYSQL_PASSWORD=mypa55 -e MYSQL_DATABASE=
- 启动服务命令: `service rabbitmq-server start`。 #### 二、配置详解 ##### 2.1 Django项目配置 在Django项目中需要配置数据库信息以便于Celery能够存储任务状态等信息。具体配置如下: - 在`settings.py`中...
- **格式**: `adb shell pm list packages [-f][-d][-e][-s][-3][-i][-u][–user USER_ID][FILTER]` - **参数说明**: - `-f`: 显示APK文件路径。 - `-d`: 只显示已启用的组件。 - `-e`: 只显示已禁用的组件。 ...
1表示Desktop Engine,2表示标准版,3表示企业版。 - instancename:返回服务器实例的名称,默认实例返回空字符串。 - productversion:返回SQL Server的版本号。 - productlevel:返回SQL Server的具体版本,如...
service mysqld start ``` 接下来是修改 root 用户密码的步骤。在安装过程中,MySQL 会自动生成一个随机的 root 密码,你可以通过以下命令查看日志文件找到这个临时密码: ``` less /var/log/mysqld.log ``` ...
app.set('view engine', 'ejs'); // 设置EJS为默认模板引擎 app.get('/profile', (req, res) => { res.render('profile', { user: 'John Doe' }); // 渲染profile.ejs并传入数据 }); ``` **6. 开发环境与生产环境*...
app.set('view engine', 'ejs'); app.set('views', './views'); app.get('/', (req, res) => { res.render('index', { title: 'Home Page' }); }); ``` 创建`views`目录和`index.ejs`文件,编写HTML内容。 七、...
3. 编写配置文件 在MySQL的解压目录下创建一个名为my.ini的配置文件,文件内容应包括设置数据库端口、安装目录、数据目录、字符集以及默认存储引擎等。例如: ``` [mysql] default-character-set=utf8 [mysqld...