.


:




:

































 

 

 

 





:

Name .

Operator name , .

Payroll (0 n ).

all prices ( ) :
(0 n ), (0 n ), (0 n ).

SMS price (0 n ).

Parameters ( )
(0 n), (12-, ),
(0 n ).

Tariff.

XML , , 4-5 . XSL TML, .

.

.

Name .

Price (0 n ).

Dosage (/).

Visual ( ) : (, , , ), (, , ), ( , , , ).

Medicine.

XML , , 4-5 . XSL TML, .

.

:

Name .

Origin .

Price (0 n ).

Type ( ) , (), ( ), ( -, ), (COM, USB, LPT).

Critical .

Device.

XML , , 4-5 . XSL XML, Critical.

.

:

Model .

Handy - .

Origin .

TTC ( ) - : ( [0 500], [500 1000 ], [1000 n ]), ( ), , .

Material .

Gun.

XML , , 4-5 . XSL XML, .

.

:

Type (, , ..).

Handy .

Origin .

Visual ( ) : ( [10 n ], [10 n ]), ( [, , ..]), ( [ , ], , ), ( ).

Value .

Knife.

XML , , 4-5 . XSL HTML, .

.

:

Model .

Origin .

Chars ( ) , : ( , , , , ), - (1 2), ( [], , : [0 10]), .

Parameters ( ), ( ), ( ).

Price ( ).

Plane.

XML , , 4-5 . XSL HTML, .

.

Name .

Energy ().

Type ( ) (, , [ ]).

Ingredients ( ) : , ( ), ( ), ( ), ( )

Value : ( .), ( .) ( .).

Production -.

Candy.

XML , , 4-5 . XSL HTML, .

.

Name .

Type (, , , ).

Al .

Manufacturer -.

Ingredients ( ) : , , , ..

Chars ( ) : - ( ), ( ), , (), ( )

Beer.

XML-, , 4-5 . XSL XML, .

.

Title .

Type (, , ).

Monthly .

Chars ( ) : ( ), (n ), ( [ ] [ ]), ( ).

Paper.

XML , , 4-5 . XSL XML, (Type).

-.

Title .

Type (, , , ).

Chars ( ) ( , ), ( ), ( ), ([ , ] ), (, -
, ).

Authorize .

Site.

XML , , 4-5 . XSL XML, (Type).

16

16.1.

XML? ( )

1. XML DTD

2. XML XSL

3. XML XSD

4. XML CSS

16.2.

XML ? ( )

1 <?xml version="1.0"?>

2 <folder>

3 <file><name><contents></contents></name></file>

4 <file><name/><contents></contents><name/></file>

5 <file><name/><contents></contents></name></file>

6 <file><name><contents/><name/></file>

7 </folder>

 

1. 1;

2. 2;

3. 3;

4. 4;

5. 5;

6. 6;

7. 7;

8. .

16.3.

XML ? ( 2)

1. <hello_dolly>;

2. <big bang>;

3. <xmldocument>;

4. <7up>;

5. .

16.4.

XML ? ( )

1. ;

2. ;

3. { };

4. [];

5. .

16.5.

SAX-?

1. ;

2. DTD-;

3. DTD-;

4. ;

5. .

 


3.

WEB-

, JSP , .

17

JSP

Sun Microsystems, 90% Java Enterprise Edition.

Java Enterprise Edition, , . , HTTP.

Servlet javax.servlet. HTTP-
HttpServlet javax.servlet.http.

. , .

init(). . , .

, .
service(HttpServletRequest req, HttpServletResponse res) , req HttpServletRequest, . res HttpServletResponse, . , service(). service() .

destroy(), .

Servlet, HttpServlet, HTTP.
service().

service() HttpServlet , . HTTP : GET, HEAD, POST, PUT, DELETE, OPTIONS TRACE. GET POST, , .

GET ( ) URL, URL. . POST (method=POST) ( ) HTTP- Content-Type.

:

<>=<>&<>=<>&...

,

enctype="multipart/form-data".

service() HttpServlet , , do: doGet() doPost(). , doHead(), doPut(), doDelete(), doOptions() doTrace(). , .

:

// # 1: : MyServlet.java

package chapt17;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

public class MyServlet extends HttpServlet {

public MyServlet() {

super ();

}

public void init() throws ServletException {

}

protected void doGet(

HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.print("This is ");

out.print(this. getClass().getName());

out.print(", using the GET method");

}

protected void doPost(

HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.print("This is ");

out.print(this. getClass().getName());

out.print(", using the POST method");

}

public void destroy() {

super. destroy(); // Just puts "destroy" string in log

}

}

HTML- , . , - . -, print(), HTML. - , , . JSP, JSPX JSF. - , .

Web-, FirstProject /WEB-INF/lasses .

Apache Tomcat JSP .
jakarta.apache.org.

Tomcat 8080, Application Server , 8082.

Tomcat 5.5.20, /Apache Software Foundation/Tomcat5.5. :

/bin tomcat5.exe,
tomcat5w.exe ;

/common , Servlet API;

/conf , server.xml;

/logs log-;

/webapps , .

/webapps /FirstProject MyServlet. , /FirstProject /WEB-INF, :

/classes chapt17.MyServlet.class;

/lib ( ), JAR- ( java);

/src MyServlet.java ();

web.xml /WEB-INF.

web.xml . , , MIME-, mapping JSP, , . , . :

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name> FirstProject </display-name>

< servlet >

<display-name> MyServletdisplay </display-name>

<servlet-name> MyServletname </servlet-name>

<servlet-class> chapt17.MyServlet </servlet-class>

</ servlet >

< servlet-mapping >

<servlet-name> MyServletname </servlet-name>

<url-pattern> /MyServlettest </url-pattern>

</ servlet-mapping >

<session-config>

<session-timeout>30</session-timeout>

</session-config>

<welcome-file-list>

<welcome-file> index.jsp </welcome-file>

</welcome-file-list>

<login-config>

<auth-method>BASIC</auth-method>

</login-config>

</web-app>

MyServletname, MyServlet.class, URL- , MyServlettest.

, :

1. cp

2. servlet-api.jar;

3. MyServlet.class /FirstProject/WEB-INF/classes/chapt18;

4. /MyProject/WEB-INF web.xml;

5. /FirstProject /webapps Tomcat;

6. Tomcat;

7. :

http://localhost:8082/FirstProject/MyServlettest

localhost IP- .

8. index.jsp, FORM :

<FORM action=" MyServlettest ">

<INPUT type="submit" value="Execute">

</FORM>

index.jsp /webapps/FirstProject
:

http://localhost:8082/FirstProject/index.jsp

JSP- URL- MyServlettest,
:

. 17.1. doGet()

JSP

Java Server Pages (JSP) , , . , , .

, JSP :

d) JSP.

e) JSP-engine JSP.

d) JSP-engine , JSP, Java _jspService(). , . JSP, .

e) *.class.

f) init() _jspService(), .

d) JSP . HTML
, JSP, ServletResponse.

JSP _jspService() . , JSP. JSP , JSP , _jspService() -.

. 17.2. JSP

JSP,
:

<!-- # 2: JSP: simple.jsp -->

<html><head>

<title>Simple</title>

</head>

<body>

<jsp:text>Hello, Bender</jsp:text>

</body></html>

:

. 17.3. index.jsp

:

// # 3: : simple_jsp.java

package org.apache.jsp;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.servlet.jsp.*;

 

public final class simple_jsp

extends org.apache.jasper.runtime.HttpJspBase

implements org.apache.jasper.runtime.JspSourceDependent{

private static java.util.List _jspx_dependants;

 

public Object getDependants() {

return _jspx_dependants;

}

public void _jspService(HttpServletRequest request,

HttpServletResponse response)

throws java.io.IOException, ServletException {

 

JspFactory _jspxFactory = null;

PageContext pageContext = null;

HttpSession session = null;

ServletContext application = null;

ServletConfig config = null;

JspWriter out = null;

Object page = this;

JspWriter _jspx_out = null;

PageContext _jspx_page_context = null;

try {

_jspxFactory = JspFactory. getDefaultFactory ();

response.setContentType("text/html");

pageContext = _jspxFactory.getPageContext(this,

request, response, null, true, 8192, true);

_jspx_page_context = pageContext;

application = pageContext.getServletContext();

config = pageContext.getServletConfig();

session = pageContext.getSession();

out = pageContext.getOut();

_jspx_out = out;

 

out.write("<html><head>\r\n");

out.write("<title>Simple</title>\r\n");

out.write("</head>\r\n");

out.write("<body>\r\n");

out.write("Hello, Bender\r\n");

out.write("</body></html>");

} catch (Throwable t) {

if (!(t instanceof SkipPageException)){

out = _jspx_out;

if (out!= null && out.getBufferSize()!= 0)

out.clearBuffer();

if (_jspx_page_context!= null) _jspx_page_context.handlePageException(t);

}

} finally {

if (_jspxFactory!= null) _jspxFactory.releasePageContext(_jspx_page_context);

}

}

}

JSP- , , . , , Java, . HTML- write(). . HTML- .

JSP

JSP . , . JSP , . , JSP-, - () , JSP .

JSP JSP.

<!-- # 4: JSP : index.jsp -->

<%@ page language="java" contentType="text/html; charset=ISO-8859-5" pageEncoding="ISO-8859-5"%>

<html><body>

<jsp:useBean id="gc" class="java.util.GregorianCalendar"/>

<jsp:getProperty name="gc" property="time"/>

<FORM action="serv" method="POST">

<INPUT type="submit" value=" ">

</FORM>

</body></html>

:

. 17.4. index.jsp

page. ction- useBean getProperty GregorianCalendar JSP . ContServlet POST.

// # 5: : ontServlet.java

package chapt17;

import java.io.IOException;

import java.util.Calendar;

import java.util.Locale;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

public class ContServlet

extends javax.servlet.http.HttpServlet {

 

protected void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

//

request.setAttribute("loc", Locale. getDefault ());

//

request.getSession().setAttribute("calend",

Calendar. getInstance ());

// RequestDispatcher JSP

request.getRequestDispatcher("/main.jsp").forward(request,

Response);

}

}

JSP , , HttpServletRequest, HttpSession, HttpServletContext. main.jsp
forward() RequestDispatcher.

<!-- # 6: , : main.jsp -->

<%@ page language="java"

contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core"

prefix="c"%>

<html><body>

<h3> </h3>

<c:out value="Locale from request: ${loc}"/><br>

<c:out value="Time from Servlet: ${calend.time}"/>

</body></html>

main.jsp :

. 17.5. main.jsp

taglib JSP Standard Tag Library (JSTL), <c:out>, Expression Language (EL) ${loc}.

web.xml :

<servlet>

<display-name>Controller</display-name>

<servlet-name>controller</servlet-name>

<servlet-class> chapt17.ContServlet </servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>controller</servlet-name>

<url-pattern> /serv </url-pattern>

</servlet-mapping>

Web-.

17

Java- JSP-, :

8. .

9. .

10. JSP .

11. .

12. . , , , .

13. , , , .

B

1 . n java.util.Random.

17

17.1.

.example.MyServlet, Web- .

1) /lib/MyServlet.class

2) /com/example/MyServlet.class

3) /WEB-INF/lib/MyServlet.class

4) classes/com/example/MyServlet.class

5) /servlets/com/example/MyServlet.lass

6) /WEB-INF/classes/com/example/MyServlet.class

17.2.

:

public void service(ServletRequest request,

ServletResponse response) {

ServletInputStream sis =

//1

}

1?

1) request.getWriter();

2) request.getReader();

3) request.getInputStream();

4) request.getResourceAsStream();

5) request.getResourceAsStream(ServletRequest. REQUEST);

17.3.

JSP JavaBean . jsp:useBean ?

1) id

2) type

3) name

4) class

5) create

17.4.

JSP?

1) <!--this is a comment-->

2) <%// this is a comment %>

3) <%-- this is a comment --%>

4) <%/** this is a comment **/%>

17.5.

doGet() HttpServlet:

public void service(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

HttpSession s = request.getSession();

// insert code here

}

?

1) session.unbind("key");

2) session.remove("key");

3) session.removeAttribute("key");

4) session.unbindAttribute("key");

5) session.deleteAttribute("key");

17.6.

- Web- ?

1) /conf/web.xml

2) /WEB-INF/web.xml

3) /conf/server.xml

4) /META-INF/web.xml

5) /WEB-INF/rules.xml

6) /META-INF/server.xml

 

 
18

, , , , HTML, JSP .

CGI ASP , , - Java, .

Web- J2EE. Servlet, , service(), init(), destroy(), :

ServletConfiggetServletConfig() , ;

String getServletInfo() .

ServletContext

ServletContext , , . , ServletContext. . , MIME- , / log-. ServletContext getServletContext().

:

String getMimeType(String filename) MIME- . MIME- text/plain, text/html;

String getRealPath(String filename) , ;

String getServerInfo() .

, (JSP, ):

Object getAttribute(String name) ;

Enumeration getAttributeNames() ;

void setAttribute(String name, Object object) ;

void removeAttribute(String name) ;

ServletContext getContext(String uripath) ;

String getServletContextName() , ServletContext.

ServletContext, , .

ServletConfig

getServletConfig(), ServletConfig, .

:

String getServletName() ;

Enumeration getInitParameterNames() web.xml;

String getInitParameter(String name) .

MyServlet, < servlet > < init-param >
:

<servlet>

<servlet-name> MyServletname </servlet-name>

<servlet-class> chapt18.MyServlet </servlet-class>

< init-param >

<param-name> mail. smtphost </param-name>

<param-value> mail.bsu </param-value>

</ init-param >

<init-param>

<param-name> mail. smtpport </param-name>

<param-value> 25 </param-value>

</init-param>

</servlet>

init() :

public void init() throws ServletException {

ServletConfig sc = getServletConfig();

 

//

Enumeration e = sc.getInitParameterNames();

while (e.hasMoreElements()) {

//

String name = (String)e.nextElement();

//

String value = sc.getInitParameter(name);

//...

}

}

ServletContext, , , :

getServletContext().getInitParameter("mail. smtpport ");

ServletRequest HttpServletRequest

HttpServletRequest. ServletRequest. ServletRequest, , HTTP,
:

String getCharacterEncoding() ;

String getContentType() MIME- (Multipurpose Internet Mail Extension) ;

String getProtocol() ;

String getServerName(), getServerPort() , , , ;

String getRemoteAddr(), getRemoteHost() IP- , , ;

String getRemoteUser() , ;

ServletInputStream getInputStream(), BufferedReader getReader() , . ServletInputStream, BufferedReader. -. getReader() getInputStream() , IllegalStateException .

, , . :

String getParameter(String name) null, ;

String[] getParameterValues(String name) ;

Enumeration getParameterNames() Enumeration.

HttpServletRequest , :

void setAttribute(String name, Object ob) , , JSP ;

Enumeration getAttributeNames() ;

Object getAttribute(String name) ;

Cookie[] getCookies() cookie, . cookie , ;

String getMethod() , ;

String getQueryString() HTTP-.

HttpServletRequest , GET .

/* # 1: : RequestServlet.java: RequestInfo.java: ClickOutput.java */

package chapt18;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.IOException;

import java.io.PrintWriter;

import java.io.UnsupportedEncodingException;

 

public class RequestServlet extends HttpServlet {

//

private int count = 0;

 

public void doGet(HttpServletRequest req,

HttpServletResponse resp)

throws ServletException {

performTask(req, resp);

}

public void doPost(HttpServletRequest req,

HttpServletResponse resp)

throws ServletException {

performTask(req, resp);

}

private void performTask(HttpServletRequest req,

HttpServletResponse resp)

throws ServletException {

try {

// MIME-

resp.setContentType("text/html; charset=Windows-1251");

 

//

PrintWriter out = resp.getWriter();

count = ClickOutput.printClick(out, count);

// -

if (count == 1)

RequestInfo.printToBrowser(out, req);

//

out.close();

} catch (UnsupportedEncodingException e) {

System.err.print("UnsupportedEncoding");

} catch (IOException e) {

System.err.print("IOErroR");

}

}

}

package chapt18;

import java.io.PrintWriter;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

 

public class RequestInfo {

static String br = "<br>";

 

public static void printToBrowser(

PrintWriter out, HttpServletRequest req) {

out.println("Method: " + req.getMethod());

out.print(br + "Request URI: " + req.getRequestURI());

out.print(br + "Protocol: " + req.getProtocol());

out.print(br + "PathInfo: " + req.getPathInfo());

out.print(br + "Remote Address: " + req.getRemoteAddr());

//

Enumeration e = req.getHeaderNames();

out.print(br + "Header INFO: ");

while (e.hasMoreElements()) {

String name = (String) e.nextElement();

String value = req.getHeader(name);

out.print(br + name + " = " + value);

}

}

}

package chapt18;

import java.io.PrintWriter;

 

public class ClickOutput {

public static int printClick(

PrintWriter out, int count) {

 

out.print(++count + " - ." + "<br>");

return count;

}

}

index.jsp URL RequestServlet.

<!-- # 2: : index.jsp-->

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-5"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional //EN">

<html><head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5">

<title>Info about Request </title>

</head><body>

<FORM action="RequestServlet" method="GET">

<INPUT type="submit" value="">

</FORM>

</body></html>

:

.

Method: GET

Request URI: /FirstProject/RequestServlet

Protocol: HTTP/1.1

PathInfo: null

Remote Address: 127.0.0.1

Header INFO:

accept = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
referer = http://localhost:8080/FirstProject/index.jsp
accept-language = ru
content-type = application/x-www-form-urlencoded
accept-encoding = gzip, deflate
user-agent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
host = localhost:8080
content-length = 0
connection = Keep-Alive
cache-control = no-cache
cookie = JSESSIONID=91014EB2B2208BCA18AE898424B71CEF

RequestServlet , .

URL, , doGet() doPost(). , HttpServletRequest, HttpServletResponse. doGet() doPost() HTTP- HTTP-, . getWriter() - PrintWriter, .

ServletResponse HttpServletResponse

- , ServletResponse, , , , .

:

ServletOutputStream getOutputStream() ServletOutputStream ;

PrintWriter getWriter() PrintWriter ;

getOutputStream() , IllegalStateException. .

HttpServletResponse, ServletResponse, :

void setContentType(String type) MIME- ;

void addCookie(Cookie c) cookie ;

void sendError(int sc, String msg) , sc , msg ;

void setDateHeader(String name, long date) ;

void setHeader(String name, String value) . , .

, . , GET.

18.1 JSP- index.jsp, /webapps/FirstProject3.

name . .

. 18.1. JSP-

radio, . , , . , , , . checked.

. .

POST, . , GET, (URL), .

<!-- # 3: : index.jsp-->

<%@ page language="java" contentType=

"text/html; charset=utf-8" pageEncoding="utf-8"%>

<html><body>

<FORM action="testform" method=POST>

<H3> :

<INPUT type="text" name=" " value="-!-">

:

<TABLE BORDER=5> <tr>

<td>JSPX</td><td><INPUT type="radio"

name=""

value="JSP XML"></td>

<td>JSTL</td><td><INPUT type="radio"

name=""

value=" JSTL"></td>

</tr></TABLE>

:

<TABLE BORDER=5> <tr>

<td>Java 6<INPUT type="radio"

name=""

value="Java SE 6"></td>

<td>Java 5<INPUT type="radio"

name=""

value="Java 1.5.0" checked></td>

</tr></TABLE></H3>

<INPUT type="submit" value=""> <BR>

</FORM>

</body></html>

FormRequest.
. , , .

/* # 4: : FormRequest.java:

ParameterOutput.java */

package chapt18;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

public class FormRequest extends HttpServlet {

protected void doPost(HttpServletRequest req,

HttpServletResponse resp)

throws ServletException {

performTask(req, resp);

}

private void performTask(HttpServletRequest req,

HttpServletResponse resp) {





:


: 2016-04-03; !; : 742 |


:

:

, .
==> ...

1738 - | 1557 -


© 2015-2024 lektsii.org - -

: 0.62 .