没有合适的资源?快使用搜索试试~ 我知道了~
关于java技术--毕业论文设计外文翻译.doc
0 下载量 174 浏览量
2023-07-10
16:10:26
上传
评论
收藏 154KB DOC 举报
温馨提示
试读
25页
关于java技术--毕业论文设计外文翻译.doc
资源推荐
资源详情
资源评论
附录一 外文资料原文:
ABOUT JAVA TECHNOLOGY
Servlets and JSP: An Overview
1. What are Java Servlets?
Servlets are Java technology's answer to CGI programming. They are programs
that run on a Web server and build Web pages. Building Web pages on the fly is
useful (and commonly done) for a number of reasons:
� The Web page is based on data submitted by the user. For example the results
pages from search engines are generated this way, and programs that process
orders for e-commerce sites do this as well.
� The data changes frequently. For example, a weather-report or news headlines
page might build the page dynamically, perhaps returning a previously built page
if it is still up to date.
� The Web page uses information from corporate databases or other such sources.
For example, you would use this for making a Web page at an on-line store that
lists current prices and number of items in stock.
2. What are the Advantage of Servlets Over "Traditional" CGI?
Java servlets are more efficient, easier to use, more powerful, more portable, and
cheaper than traditional CGI and than many alternative CGI-like technologies. (More
importantly, servlet developers get paid more than Perl programmers :-).
� Efficient. With traditional CGI, a new process is started for each HTTP request. If
the CGI program does a relatively fast operation, the overhead of starting the process
can dominate the execution time. With servlets, the Java Virtual Machine stays up,
and each request is handled by a lightweight Java thread, not a heavyweight operating
system process. Similarly, in traditional CGI, if there are N simultaneous request to
the same CGI program, then the code for the CGI program is loaded into memory N
times. With servlets, however, there are N threads but only a single copy of the servlet
class. Servlets also have more alternatives than do regular CGI programs for
optimizations such as caching previous computations, keeping database connections
open, and the like.
� Convenient. Hey, you already know Java. Why learn Perl too? Besides the
convenience of being able to use a familiar language, servlets have an extensive
infrastructure for automatically parsing and decoding HTML form data, reading and
setting HTTP headers, handling cookies, tracking sessions, and many other such
utilities.
� Powerful. Java servlets let you easily do several things that are difficult or
impossible with regular CGI. For one thing, servlets can talk directly to the Web
server (regular CGI programs can't). This simplifies operations that need to look up
images and other data stored in standard places. Servlets can also share data among
each other, making useful things like database connection pools easy to implement.
They can also maintain information from request to request, simplifying things like
session tracking and caching of previous computations.
� Portable. Servlets are written in Java and follow a well-standardized API.
Consequently, servlets written for, say I-Planet Enterprise Server can run virtually
unchanged on Apache, Microsoft IIS, or WebStar. Servlets are supported directly or
via a plugin on almost every major Web server.
� Inexpensive. There are a number of free or very inexpensive Web servers
available that are good for "personal" use or low-volume Web sites. However, with
the major exception of Apache, which is free, most commercial-quality Web servers
are relatively expensive. Nevertheless, once you have a Web server, no matter the cost
of that server, adding servlet support to it (if it doesn't come preconfigured to support
servlets) is generally free or cheap.
3. What is JSP?
Java Server Pages (JSP) is a technology that lets you mix regular, static HTML
with dynamically-generated HTML. Many Web pages that are built by CGI programs
are mostly static, with the dynamic part limited to a few small locations. But most
CGI variations, including servlets, make you generate the entire page via your
program, even though most of it is always the same. JSP lets you create the two parts
separately. Here's an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Welcome to Our Store</TITLE></HEAD>
<BODY>
<H1>Welcome to Our Store</H1>
<SMALL>Welcome,
<!-- User name is "New User" for first-time visitors -->
<% out.println(Utils.getUserNameFromCookie(request)); %>
To access your account settings, click
<A HREF="Account-Settings.html">here.</A></SMALL>
<P>
Regular HTML for all the rest of the on-line store's Web page.
</BODY></HTML>
4. What are the Advantages of JSP?
� vs. Active Server Pages (ASP). ASP is a similar technology from Microsoft. The
advantages of JSP are twofold. First, the dynamic part is written in Java, not Visual
Basic or other MS-specific language, so it is more powerful and easier to use. Second,
it is portable to other operating systems and non-Microsoft Web servers.
� vs. Pure Servlets. JSP doesn't give you anything that you couldn't in principle do
with a servlet. But it is more convenient to write (and to modify!) regular HTML than
to have a zillion println statements that generate the HTML. Plus, by separating the
look from the content you can put different people on different tasks: your Web page
design experts can build the HTML, leaving places for your servlet programmers to
insert the dynamic content.
� vs. Server-Side Includes (SSI). SSI is a widely-supported technology for
including externally-defined pieces into a static Web page. JSP is better because it lets
you use servlets instead of a separate program to generate that dynamic part. Besides,
SSI is really only intended for simple inclusions, not for "real" programs that use form
data, make database connections, and the like.
� vs. JavaScript. JavaScript can generate HTML dynamically on the client. This is a
useful capability, but only handles situations where the dynamic information is based
on the client's environment. With the exception of cookies, HTTP and form
submission data is not available to JavaScript. And, since it runs on the client,
JavaScript can't access server-side resources like databases, catalogs, pricing
information, and the like.
� vs. Static HTML. Regular HTML, of course, cannot contain dynamic information.
JSP is so easy and convenient that it is quite feasible to augment HTML pages that
only benefit marginally by the insertion of small amounts of dynamic data. Previously,
the cost of using dynamic data would preclude its use in all but the most valuable
instances.
Overview
JavaServer Pages (JSP) lets you separate the dynamic part of your pages from
the static HTML. You simply write the regular HTML in the normal manner, using
whatever Web-page-building tools you normally use. You then enclose the code for
the dynamic parts in special tags, most of which start with "<%" and end with "%>".
For example, here is a section of a JSP page that results in something like "Thanks for
ordering Core Web Programming"for URL of
http://host/OrderConfirmation.jsp?title=Core+Web+Programming:
Thanks for ordering a
<I><%= request.getParameter("title") %></I>
You normally give your file a .jsp extension, and typically install it in any place
you could place a normal Web page. Although what you write often looks more like a
regular HTML file than a servlet, behind the scenes, the JSP page just gets converted
to a normal servlet, with the static HTML simply being printed to the output stream
associated with the servlet's service method. This is normally done the first time the
page is requested, and developers can simply request the page themselves when first
installing it if they want to be sure that the first real user doesn't get a momentary
delay when the JSP page is translated to a servlet and the servlet is compiled and
loaded. Note also that many Web servers let you define aliases that so that a URL that
appears to reference an HTML file really points to a servlet or JSP page.
剩余24页未读,继续阅读
资源评论
黑色的迷迭香
- 粉丝: 718
- 资源: 4万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功