Java Servlet Programming and Application of seven
天æžIT information SMS services small computer skills
Java keyword navigation network J2ME mobile phone games JavaCard Struts JAAS EJB JavaMail game Analyzer J2EE Design Pattern
Server-side includes (Server-Side Includes) is a Web page design in a commonly used technology, in a lot of web output systems, often have some of the components of the Web page over at the same time. Server-Side Includes Java Server architecture is a high-level features, it can be embedded in HTML documents servlet so you can use one or more servlet component to the final HTML document, which contains a special output Servlet HTML tag and the extension of documents. shtml said.
Servlet marked script:
<Servlet_name code servlet name = = = Servlet.class codebase path name of a parameter value = 1
Name 2 = parameter values 2
……..
Name parameter values n = n>
<A name = param name = value parameter values 1
2 param name = name = value parameter value 2
……..
Param name = name n value of parameters n =>
</ Servlet>
Programming ideas and skills: Below is a complete server contains simple (SSI) example, the entire shtml pages from two Servlet component, a Servlet is Header.java, on behalf of the first page, the main function is to Title Information is the first two Servlet Footer.java behalf footer, the main function is to show footer copyright information; Together.shtml is to combine two Servlet display server contains, it should file from the root directory (such as wwwroot) loading.
Header.java standard of the first page of the source code as follows:
Import javax.servlet .*;
Import java.io. *;
Public class Header extends GenericServlet
(
Public void service (ServletRequest req, ServletResponse resp)
Throws ServletException, IOException
(
Res.setContentType ( "text / html; charset = gb2312");
PrintWriter out = res.getWriter ();
/ / Get the title of the page. Set to empty string if
/ / No title parameter was given
String titles [] = req.getParameterValues ( "title");
String title = "";
If (titles! = Null) (
If (titles.length> 0) (
Title = titles [0];
)
)
/ / Format the standard header
Out.println ( "<head> <title> welcome your arrival </ title> </ head>");
Out.println ( "<H1 align='center'> welcome your arrival *** *** </ H1> <hr>");
/ / Wrap up
Out.flush ();
Out.close ();
)
/ **
* <p> Returns information about this servlet
* /
Public String getServletInfo () (
Return "Header";
)
Public void init (ServletConfig cfg)
Throws ServletException
(
Super.init (cfg);
)
Public void destroy ()
(
Super.destroy ();
)
)
Standard footer Footer.java the source code as follows:
Import javax.servlet .*;
Import java.io. *;
Public class Footer extends GenericServlet
(
Public void service (ServletRequest req, ServletResponse resp)
Throws ServletException, IOException
(
Res.setContentType ( "text / html; charset = gb2312");
PrintWriter out = res.getWriter ();
/ / Format the standard header
Out.println ( "<hr>");
Out.println ( "<p align='center'> <i> Copyright Company </ i> </ p>");
/ / Wrap up
Out.flush ();
Out.close ();
)
/ **
* <p> Returns information about this servlet
* /
Public String getServletInfo () (
Return "Footer";
)
Public void init (ServletConfig cfg)
Throws ServletException
(
Super.init (cfg);
)
Public void destroy ()
(
Super.destroy ();
)
)
Together.shtml server contains the source code as follows:
<html>
<servlet Code=Header>
<param Name="title" value="GOOD">
</ Servlet>
<body>
<dir>
This a study programmer!; <br>
Are you Interested in?; <br>
Let's go Research. <br>
</ Dir>
<servlet Code=Footer>
</ Servlet>
</ Body>
</ Html>
Tags: java programming ideas, java programming language
Releated Java Articles
December 31, 2005 | Filed Under Core Java |






