JSP/servlet Study Notes (4)

Source: Internet
Author: User
Tags tld

The publishing process of a Web application

1. Deploy HTML files

Add the index.htm file to the helloappdirectory.

 

2. Deploy JSP

Common JSP files, under the helloapp directory.

 

3. Deploy Servlet

(1) create a Servlet File. It can call the getparameter method of the httpservletrequest object to read the loginform data submitted by the customer.

(2 ). compile this Java file, compile the servlet-api.jar file. copy the compiled class file to the "/helloapp/WEB-INF/classes/mypackage" directory. (mypackage is the package to which this class belongs ).

(3) Add the <servlet> and <servlet-mapping> elements to the class in Web. xml.

 

<Servlet> attributes of an element

<Servlet-Name> Define servlet name
<Servelt-class> Specify the servlet class
<Init-param> Defines servlet initialization parameters (including parameter names and values). Multiple <init-param>
<Load-on-startup> Specify the servlet loading order when the web application starts. When the value is positive or 0, the servlet container first loads a servlet with a small value. if this value is negative or not set, the servlet container will load the servlet when the Web client accesses the servlet for the first time.

<Servlet-mapping> specifies the <servlet-Name> and <URL-pattern> mappings.

<URL-pattern> indicates the relative URL path to access the servlet.

 

4. Deploy JSP tag Library

Add Tag library to Web applications ). tag Library provides users with the ability to customize JSP tags. we will define a tag library named mytaglib, which contains a simple hello tag, which can resolve all <mm: Hello/> in JSP to the string "hello ".

Follow these steps to create and release the mytaglib tag Library:

(1) Compile hellotag. Java class for processing Hello labels.

  1. Package mypackage;
  2. Import javax. servlet. jsp. jspexception;
  3. Import javax. servlet. jsp. jsptagexception;
  4. Import javax. servlet. jsp. tagext. tagsupport;
  5. Pubilc class hellotag extends tagsupport
  6. {
  7. Public void hellotag (){}
  8. Public int doendtag () throws jspexception {
  9. Try {
  10. Pagecontext. getout (). Print ("hello ");
  11. }
  12. Catch (exception e ){
  13. Throw new jsptagexception (E. getmessage ();
  14. }
  15. Return skip_body;
  16. }
  17. Public void release (){
  18. Super. Release ();
  19. }
  20. }

(1). Compile hellotag. Java, the need for jsp-api.jar files. Compile the generated hellotage. Class storage location for/WEB-INF/classes/mypackage/hellotag. Class.

(2) Create the description file mytaglib. TLD of the tag library.

<? XML version = "1.0" encoding = "ISO-8859-1"?>

<! Doctype taglib...>

<Taglib>

<Tlibversion> 1.0 </tlibversion>

<Jspversion> 1.1 </jspversion>

<Shortname> mytaglib </shortname

<URL>/mytaglib </URL>

 

<Tag>

<Name> Hello </Name>

<Tagclass> mypackage. hellotag </tagcalss>

Bodycontent> Empty </bodycontent>

<Info> just says hello </INFO>

</Tag>

 

</Taglib>

 

(3) Add the <taglib> element to the Web. xml file.

<? XML...>

<! Doctype web-app...>

<Web-app>

<Servlet>

........

</Servlet>

 

<Taglib>

<Taglib-URL>/mytaglib </taglib-URL>

/WEB-INF/mytaglib. TLD </taglib-location>

</Taglib>

</Web-app>

 

<Taglib-URL> specify tag library> identifier. <taglib-location> specify the location of the tag library description file (TLD.

 

(4) Add the hello tag to the hello. JAP file, and first display the taglib command of mytaglib.

<% @ Taglib url = "/mytaglib" prefix = "mm" %>

The following <mm: Hello/> output will be hello.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.