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.
- Package mypackage;
- Import javax. servlet. jsp. jspexception;
- Import javax. servlet. jsp. jsptagexception;
- Import javax. servlet. jsp. tagext. tagsupport;
- Pubilc class hellotag extends tagsupport
- {
- Public void hellotag (){}
- Public int doendtag () throws jspexception {
- Try {
- Pagecontext. getout (). Print ("hello ");
- }
- Catch (exception e ){
- Throw new jsptagexception (E. getmessage ();
- }
- Return skip_body;
- }
- Public void release (){
- Super. Release ();
- }
- }
(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.