欢迎来到得力文库 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
得力文库 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    毕业论文外文翻译-JSP基础学习资料.docx

    • 资源ID:29918667       资源大小:51.65KB        全文页数:16页
    • 资源格式: DOCX        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    毕业论文外文翻译-JSP基础学习资料.docx

    JSP基础学习资料一、 JSP 技术概述 在 Sun 正式发布 JSP(JavaServer Pages) 之后,这种新的 Web 应用开发技术很快引起了人们的关注。 JSP 为创建高度动态的 Web 应用提供了一个独特的开发环境。按照 Sun 的说法, JSP 能够适应市场上包括 Apache WebServer 、 IIS4.0 在内的 85% 的服务器产品。即使您对 ASP “一往情深”,我们认为,关注 JSP 的发展仍旧很有必要。 JSP 与 ASP 的简单比较 JSP 与 Microsoft 的 ASP 技术非常相似。两者都提供在 HTML 代码中混合某种程序代码、由语言引擎解释执行程序代码的能力。在 ASP 或 JSP 环境下, HTML 代码主要负责描述信息的显示样式,而程序代码则用来描述处理逻辑。普通的 HTML 页面只依赖于 Web 服务器,而 ASP 和 JSP 页面需要附加的语言引擎分析和执行程序代码。程序代码的执行结果被重新嵌入到 HTML 代码中,然后一起发送给浏览器。 ASP 和 JSP 都是面向 Web 服务器的技术,客户端浏览器不需要任何附加的软件支持。 ASP 的编程语言是 VBScript 之类的脚本语言, JSP 使用的是 Java ,这是两者最明显的区别。此外, ASP 与 JSP 还有一个更为本质的区别:两种语言引擎用完全不同的方式处理页面中嵌入的程序代码。在 ASP 下, VBScript 代码被 ASP 引擎解释执行;在 JSP 下,代码被编译成 Servlet 并由 Java 虚拟机执行,这种编译操作仅在对 JSP 页面的第一次请求时发生。 运行环境 Sun 公司的 JSP 主页在 ,从这里还可以下载 JSP 规范,这些规范定义了供应商在创建 JSP 引擎时所必须遵从的一些规则。 执行 JSP 代码需要在服务器上安装 JSP 引擎。此处我们使用的是 Sun 的 JavaServer Web Development Kit ( JSWDK )。为便于学习,这个软件包提供了大量可供修改的示例。安装 JSWDK 之后,只需执行 startserver 命令即可启动服务器。在默认配置下服务器在端口 8080 监听,使用 http:/localhost:8080 即可打开缺省页面。 在运行 JSP 示例页面之前,请注意一下安装 JSWDK 的目录,特别是“ work ”子目录下的内容。执行示例页面时,可以在这里看到 JSP 页面如何被转换成 Java 源文件,然后又被编译成 class 文件(即 Servlet )。 JSWDK 软件包中的示例页面分为两类,它们或者是 JSP 文件,或者是包含一个表单的 HTML 文件,这些表单均由 JSP 代码处理。与 ASP 一样, JSP 中的 Java 代码均在服务器端执行。因此,在浏览器中使用“查看源文件”菜单是无法看到 JSP 源代码的,只能看到结果 HTML 代码。所有示例的源代码均通过一个单独的“ examples ”页面提供。 JSP 页面示例 下面我们分析一个简单的 JSP 页面。您可以在 JSWDK 的 examples 目录下创建另外一个目录存放此文件,文件名字可以任意,但扩展名必须为 .jsp 。从下面的代码清单中可以看到, JSP 页面除了比普通 HTML 页面多一些 Java 代码外,两者具有基本相同的结构。 Java 代码是通过 < % 和 %> 符号加入到 HTML 代码中间的,它的主要功能是生成并显示一个从 0 到 9 的字符串。在这个字符串的前面和后面都是一些通过 HTML 代码输出的文本。 < HTML> < HEAD>< TITLE>JSP 页面 < /TITLE>< /HEAD> < BODY> < % page language="java" %> < %! String str="0" %> < % for (int i=1; i < 10; i+) str = str + i; %> JSP 输出之前。 < P> < %= str %> < P> JSP 输出之后。 < /BODY> < /HTML> 这个 JSP 页面可以分成几个部分来分析。 首先是 JSP 指令。它描述的是页面的基本信息,如所使用的语言、是否维持会话状态、是否使用缓冲等。 JSP 指令由 < % 开始, %> 结束。在本例中,指令“ < % page language="java" %> ”只简单地定义了本例使用的是 Java 语言(当前,在 JSP 规范中 Java 是唯一被支持的语言)。 接下来的是 JSP 声明。 JSP 声明可以看成是定义类这一层次的变量和方法的地方。 JSP 声明由 < %! 开始, %> 结束。如本例中的“ < %! String str="0" %> ”定义了一个字符串变量。在每一项声明的后面都必须有一个分号,就象在普通 Java 类中声明成员变量一样。 位于 < % 和 %> 之间的代码块是描述 JSP 页面处理逻辑的 Java 代码,如本例中的 for 循环所示。 最后,位于 < %= 和 %> 之间的代码称为 JSP 表达式,如本例中的“ < %= str %> ”所示。 JSP 表达式提供了一种将 JSP 生成的数值嵌入 HTML 页面的简单方法。 二、会话状态管理 会话状态维持是 Web 应用开发者必须面对的问题。有多种方法可以用来解决这个问题,如使用 Cookies 、隐藏的表单输入域,或直接将状态信息附加到 URL 中。 Java Servlet 提供了一个在多个请求之间持续有效的会话对象,该对象允许用户存储和提取会话状态信息。 JSP 也同样支持 Servlet 中的这个概念。 在 Sun 的 JSP 指南 中可以看到许多有关隐含对象的说明(隐含的含义是,这些对象可以直接引用,不需要显式地声明,也不需要专门的代码创建其实例)。例如 request 对象,它是 HttpServletRequest 的一个子类。该对象包含了所有有关当前浏览器请求的信息,包括 Cookies , HTML 表单变量等等。 session 对象也是这样一个隐含对象。这个对象在第一个 JSP 页面被装载时自动创建,并被关联到 request 对象上。与 ASP 中的会话对象相似, JSP 中的 session 对象对于那些希望通过多个页面完成一个事务的应用是非常有用的。 为说明 session 对象的具体应用,接下来我们用三个页面模拟一个多页面的 Web 应用。第一个页面( q1.html )仅包含一个要求输入用户名字的 HTML 表单,代码如下: < HTML> < BODY> < FORM METHOD=POST ACTION="q2.jsp"> 请输入您的姓名: < INPUT TYPE=TEXT NAME="thename"> < INPUT TYPE=SUBMIT VALUE="SUBMIT"> < /FORM> < /BODY> < /HTML> 第二个页面是一个 JSP 页面( q2.jsp ),它通过 request 对象提取 q1.html 表单中的 thename 值,将它存储为 name 变量,然后将这个 name 值保存到 session 对象中。 session 对象是一个名字 / 值对的集合,在这里,名字 / 值对中的名字为“ thename ”,值即为 name 变量的值。由于 session 对象在会话期间是一直有效的,因此这里保存的变量对后继的页面也有效。 q2.jsp 的另外一个任务是询问第二个问题。下面是它的代码: < HTML> < BODY> < % page language="java" %> < %! String name="" %> < % name = request.getParameter("thename"); session.putValue("thename", name); %> 您的姓名是: < %= name %> < p> < FORM METHOD=POST ACTION="q3.jsp"> 您喜欢吃什么 ? < INPUT TYPE=TEXT NAME="food"> < P> < INPUT TYPE=SUBMIT VALUE="SUBMIT"> < /FORM> < /BODY> < /HTML> 第三个页面也是一个 JSP 页面( q3.jsp ),主要任务是显示问答结果。它从 session 对象提取 thename 的值并显示它,以此证明虽然该值在第一个页面输入,但通过 session 对象得以保留。 q3.jsp 的另外一个任务是提取在第二个页面中的用户输入并显示它: < HTML> < BODY> < % page language="java" %> < %! String food="" %> < % food = request.getParameter("food"); String name = (String) session.getValue("thename"); %> 您的姓名是: < %= name %> < P> 您喜欢吃: < %= food %> < /BODY> < /HTML> 三、引用 JavaBean 组件 JavaBean 是一种基于 Java 的软件组件。 JSP 对于在 Web 应用中集成 JavaBean 组件提供了完善的支持。这种支持不仅能缩短开发时间(可以直接利用经测试和可信任的已有组件,避免了重复开发),也为 JSP 应用带来了更多的可伸缩性。 JavaBean 组件可以用来执行复杂的计算任务,或负责与数据库的交互以及数据提取等。如果我们有三个 JavaBean ,它们分别具有显示新闻、股票价格、天气情况的功能,则创建包含所有这三种功能的 Web 页面只需要实例化这三个 Bean ,使用 HTML 表格将它们依次定位就可以了。 为说明在 JSP 环境下 JavaBean 的应用,我们创建了一个名为 TaxRate 的 Bean 。它有两个属性,即 Product (产品)和 Rate (税率)。两个 set 方法分别用来设置这两个属性,两个 get 方法则用于提取这两个属性。在实际应用中,这种 Bean 一般应当从数据库提取税率值,此处我们简化了这个过程,允许任意设定税率。下面是这个 Bean 的代码清单: package tax; public class TaxRate String Product; double Rate; public TaxRate() this.Product = "A001" this.Rate = 5; public void setProduct (String ProductName) this.Product = ProductName; public String getProduct() return (this.Product); public void setRate (double rateValue) this.Rate = rateValue; public double getRate () return (this.Rate); 在 JSP 页面中应用上述 Bean 要用到 < jsp:useBean> 标记。依赖于具体使用的 JSP 引擎的不同,在何处配置以及如何配置 Bean 的方法也可能略有不同。本文将这个 Bean 的 .class 文件放在 c:jswdk-1.0examplesWEB-INFjspeans ax 目录下,这里的 tax 是一个专门存放该 Bean 的目录。下面是一个应用上述 Bean 的示例页面: < HTML> < BODY> < % page language="java" %> < jsp:useBean id="taxbean" scope="application" class="tax.TaxRate" /> < % taxbean.setProduct("A002"); taxbean.setRate(17); %> 使用方法 1 : < p> 产品 : < %= taxbean.getProduct() %> < br> 税率 : < %= taxbean.getRate() %> < p> < % taxbean.setProduct("A003"); taxbean.setRate(3); %> < b> 使用方法 2 : < /b> < p> 产品 : < jsp:getProperty name="taxbean" property="Product" /> < br> 税率 : < jsp:getProperty name="taxbean" property="Rate" /> < /BODY> < /HTML> 在 < jsp:useBean> 标记内定义了几个属性,其中 id 是整个 JSP 页面内该 Bean 的标识, scope 属性定义了该 Bean 的生存时间, class 属性说明了该 Bean 的类文件(从包名开始)。 这个 JSP 页面不仅使用了 Bean 的 set 和 get 方法设置和提取属性值,还用到了提取 Bean 属性值的第二种方法,即使用 < jsp:getProperty> 标记。 < jsp:getProperty> 中的 name 属性即为 < jsp:useBean> 中定义的 Bean 的 id ,它的 property 属性指定的是目标属性的名字。 事实证明, Java Servlet 是一种开发 Web 应用的理想构架。 JSP 以 Servlet 技术为基础,又在许多方面作了改进。 JSP 页面看起来象普通 HTML 页面,但它允许嵌入执行代码,在这一点上,它和 ASP 技术非常相似。利用跨平台运行的 JavaBean 组件, JSP 为分离处理逻辑与显示样式提供了卓越的解决方案。 JSP 必将成为 ASP 技术的有力竞争者。The JSP basic learning material1. JSP technology overviewIn from the official launch JSP (JavaServer Web), then the new Web application development skills quickly to cause the attention of people. The JSP for creating highly dynamic Web application provides a unique development environment. According to the statement from can adapt to the market, the JSP WebServer, including I can with Apache IIS4.0, 85% of server products. Even if you the ASP "madly", we believe, paying attention to the development of JSP are still very be necessary.(1)JSP simple compared with ASPThe JSP and Microsoft of ASP technology are very similar. Both offer in HTML code mixed some code, by the language engine interpretive execution code's ability. In ASP and JSP environment, HTML code is mainly responsible for describe information display, and program code is used to describe handling logic. Normal HTML page only depends on the Web server and the ASP and JSP page need additional language engine analysis and implementation program code. The program code to be executing embedded into HTML code, then the message to all browsers. ASP and JSP are facing the Web server technology, the client browser does not need any additional software support.ASP programming language is VBScript such scripting language, JSP use is Java, this is both one of the most significant differences. In addition, ASP and JSP more essential difference: two languages in a totally different way engine handling page embedded program code. In the ASP, VBScript code is ASP engines interpret execution; In the JSP, code has been compiled into Java virtual machine by Servlet and execution, the compiler operation is only on the JSP page first request happen.(2)Dimension of running environmentFrom the JSP page in from here can also download the JSP specification, these standard defines the supplier in creating JSP engine when must comply to some rules.Execute JSP code needed on the server installation JSP engine. Here we use is from the Development Kit (JavaServer Web JSWDK). To facilitate learning, this package offers a lot for modification examples. JSWDK after installation, just need to perform startserver command can server. The default configuration server in the port 8080 surveillance, use http:/localhost:8080 can open default page.In running the JSP sample page before installation, please pay attention to the JSWDK directory, especially "schools" subdirectories of content. Execute the sample pages, here can see how the JSP page are converted into Java source file, then compiled into scale-up file (i.e. Servlet). JSWDK packages examples in the page is divided into two categories, they or JSP files, or is included in a form of HTML files, these forms all by JSP code processing. And as the Java, JSP ASP code are executed on the server. Therefore, in the browser use "the view source" menu is unable to see the JSP code, can see the results HTML code. All the source code examples are by a single "provide examples" page.Eclipse is an open source, based on a Java extensible development platform. Eclipse it just a framework and a set of service, used to construct the Development environment through plug-ins components, the key is Eclipse comes in a standard plugin sets, including Java Development Tools (Java Development Tools, JDT). The Eclipse is developed by IBM alternative commercial software for the next generation of Java Visual age-related IDE development environment, November 2001 contribution to the open source community, now by a non-profit software vendors alliance Eclipse Foundation (Eclipse Foundation) management.(3)JSP page examples Below we analyze a simple JSP page. You can JSWDK examples in the directory create another directory store this file, the file name can be arbitrary, but extensions must serve. JSP. From the code below the list can see, except the JSP page than ordinary HTML page more Java code outside, both has the same basic structure. Java code is through < % and % > symbols to join in the middle of the HTML code, its main function is to generate and display a from 0 to 9 string. In the string in the front and rear of the HTML code that some are through the text output. < HTML> < HEAD>< TITLE>JSP PAGE < /TITLE>< /HEAD> < BODY> < % page language="java" %> < %! String str="0" %> < % for (int i=1; i < 10; i+) str = str + i; %> JSP Before out。 < P> < %= str %> < P> JSP After out。 < /BODY> < /HTML> The JSP page can be divided into several parts for analysis.First is the JSP instructions. It describes the basic information of the page, such as the use of language, whether to maintain conversation status, whether to use cushion etc. The JSP instructions by < % beginning, % > over. In this example, directive "< % brief language =" Java "% >" simply defines this example is using Java language (at present, in the JSP specification in Java is the only support language).Next came the JSP statement. The JSP statement may be regarded as the definition of this level of variables and method of place. The JSP statement by < %! Start, % > over. If the cases of "< %! String STR =" 0 " % > "defines a String variable. In every statement behind must have a semicolon, just like in ordinary Java class declaration in the same member variables.Located in < % and % > between the code block is to describe the JSP page handling logic of Java code, such as the example shown the seas cycle.Finally, located in < % = and % > between code is called the JSP expression, such as the example of "< % = STR % >" below. The JSP expression provides a will JSP generated numerical embedded HTML pages of simple method.2. The session state managementThe session state maintain is the Web application developers must face the problem. There are various ways can be used to solve this problem, if use Cookies, hidden form input domain, or directly to the URL in additional status information. Java Servlet provides a continuous effectively in multiple requests the conversation between objects, the object allows users to store and retrieve the session state information. The JSP also support Servlet of this concept.In the JSP from guidelines can see many relevant implied object instructions (implicit meaning is that these objects can directly referenced, do not need explicit statement, also do not need special code to create actually cases). For example that object, it is the HttpServletRequest a derived class. The object contains all the related current browser requests information, including Cookies, HTML form variables, etc. Session object is also such a hidden objects. This object in the first JSP page is loaded, and automatically created by related to that objects. The conversation with ASP object of similar, JSP session object for those who hope that through multiple pages to complete a affairs application is very useful.To illustrate the session object concrete application, next we use three pages more than a page of simulation Web application. The first page (q1. HTML) contain only a requirement to enter your user name HTML forms, the HTML code is as follows: < HTML> < BODY> < FORM METHOD=POST ACTION="q2.jsp"> Please write your name: < INPUT TYPE=TEXT NAME="thename"> < INPUT TYPE=SUBMIT VALUE="SUBMIT"> < /FORM> < /BODY> < /HTML> The second page is a JSP page (q2. JSP), it through that object extraction in q1. HTML form thename value, it will be stored for name variable, then will the name value saved to the session objects. Session object is a name/value pairs set, here, name/value pairs of the name is "thename", namely for name values of the value of the variable. Due in session during the session object is effective until, so here preserved variables on subsequent page as well. Q2. JSP another task is to ask the second question. Below is its code: < HTML> < BODY> < % page language="java" %> < %! String name="" %> < % name = request.getParameter("thename"); session.putValue("thename", name); %> What is your name: < %= name %> < p> < FORM METHOD=POST ACTION="q3.jsp"> What do you want to eat? < INPUT TYPE=TEXT NAME="food"> < P> < INPUT TYPE=SUBMIT VALUE="SUBMIT"> < /FORM> < /BODY> < /HTML> The third page is a JSP page (percentile. JSP), main task is to show the q&a results. It from the value of the

    注意事项

    本文(毕业论文外文翻译-JSP基础学习资料.docx)为本站会员(豆****)主动上传,得力文库 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知得力文库 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于得利文库 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

    © 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

    黑龙江省互联网违法和不良信息举报
    举报电话:0468-3380021 邮箱:hgswwxb@163.com  

    收起
    展开