额,最近也是心血来潮准备翻译一个java web的系列博客,这是第一篇。虽然原文很简单,也没什么生词,但是这么一大堆文字能翻一来,我还是比较佩服自己的耐心的,嘿嘿,特别是这上传图片,简直太CD了,不管怎么说,还是有点小收获的,不光是锻炼了我的英语水平(⊙﹏⊙b汗),而且在翻译中我发现外国人写博客真的是好用心啊,从那些截图就可以看出来(我偷懒了,部分图没有贴),每一步都很认真,而且他们的博客都很有条理性,每个知识点都能罗列出几条要点。另外还有个感受是博客很完整,譬如我翻译的这篇就是java web系列的第一篇,往后还有好多篇,我也大致看了下,知识点都很完整。
再来看下咱国人的博客,虽不乏精品,但是我所见的大部分都是你抄我我抄你,而且好多文章都没有条理性或者更偷懒一点的直接贴上几百行代码(额,比如我。。。),这一点咱真得好好跟外国人学学呢。。
---------------------------------------------------------------------------------------------------------------------------------------------
web应用一般是指动态的web站点。java通过jsp与servlet技术为创建动态web站点提供了支持。我们当然可以使用纯静态的html网页来组建我们的网站,但是当网站的某些信息时刻变化的时候,仅仅通过html已经满足不了我们的需求,所以我们会使用诸如jsp、asp、php等技术来实现动态信息的展示以及与用户更好的交互。
1
2
3
|
GET
/FirstServletProject/jsps/hello
.jsp HTTP
/1
.1
Host: localhost:8080
Cache-Control: no-cache
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
200 OK
Date: Wed, 07 Aug 2013 19:55:50 GMT
Server: Apache-Coyote/1.1
Content-Length: 309
Content-Type: text/html;charset=US-ASCII
<!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=US-ASCII"
>
<
title
>Hello</
title
>
</
head
>
<
body
>
<
h2
>Hi There!</
h2
>
<
br
>
<
h3
>Date=Wed Aug 07 12:57:55 PDT 2013
</
h3
>
</
body
>
</
html
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package
com.journaldev.first;
import
java.io.IOException;
import
java.io.PrintWriter;
import
java.util.Date;
import
javax.servlet.ServletException;
import
javax.servlet.annotation.WebInitParam;
import
javax.servlet.annotation.WebServlet;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class FirstServlet
*/
@WebServlet
(description =
"My First Servlet"
, urlPatterns = {
"/FirstServlet"
,
"/FirstServlet.do"
}, initParams = {
@WebInitParam
(name=
"id"
,value=
"1"
),
@WebInitParam
(name=
"name"
,value=
"pankaj"
)})
public
class
FirstServlet
extends
HttpServlet {
private
static
final
long
serialVersionUID = 1L;
public
static
final
String HTML_START=
"<html><body>"
;
public
static
final
String HTML_END=
"</body></html>"
;
/**
* @see HttpServlet#HttpServlet()
*/
public
FirstServlet() {
super
();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected
void
doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException {
PrintWriter out = response.getWriter();
Date date =
new
Date();
out.println(HTML_START +
"<h2>Hi There!</h2><br/><h3>Date="
+date +
"</h3>"
+HTML_END);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected
void
doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException {
// TODO Auto-generated method stub
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!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=US-ASCII"
>
<
title
>Hello</
title
>
</
head
>
<
body
>
<
h2
>Hi There!</
h2
>
<
br
>
<
h3
>Date=<%= new Date() %>
</
h3
>
</
body
>
</
html
>
|