Разработка контента курса дистанционного обучения "DB2 универсальная база данных", страница 41

                                                      MultiPartParser.java

JSP-страницы

index.jsp

<%@ page contentType="text/html; charset=windows-1251"%>

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

<HTML>

<HEAD>

<META http-equiv="Content-Style-Type" content="text/css">

<META http-equiv="cache-control" content="no-store">

<META http-equiv="pragma" content="no-cache">

<LINK href="css/content.css" rel="stylesheet" type="text/css">

<TITLE>Страница загрузки XML-файла с данными для репликации</TITLE>

</HEAD>

<BODY>

    <h2>АСУ ЛР: Репликация</h2>

      <form name="loadForm" method="post" enctype="multipart/form-data" action="receiver">

        Укажите XML-файл:<br>

            <input id="1" size="60" name="xmlFile" type="File"><br><br>

            <input id="2" name="button" type="Submit" value="Отправить">

      </form>

    <br>

    <a href="journal">Журнал SQL-операций</a>

</BODY>

</HTML>

error.jsp

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

<%@ page contentType="text/html; charset=windows-1251"%>

<HTML>

<HEAD>

<META http-equiv="Content-Style-Type" content="text/css">

<META http-equiv="cache-control" content="no-store">

<META http-equiv="pragma" content="no-cache">

<LINK href="css/error.css" rel="stylesheet" type="text/css">

<TITLE>Ошибка</TITLE>

</HEAD>

<BODY>

<%

    String error = (String)session.getAttribute("ERR");

    String errorDescription = (String)session.getAttribute("ERR_DESCRIPTION");

%>

    <table>

        <tr>

            <td>

                <h4>

                    АСУ ЛР: Репликация<br>

                </h4>

                <h5>

                    <%=error%><br><br>

                    <%=errorDescription%><br>

                    Сообщите об этом Вашему системному администратору<br>

                </h5>

            </td>

        </tr>

        <tr>

            <td>

                <a href="index.jsp">Переход на начальную страницу</a>

            </td>

        <tr>

    </table>

</BODY>

</HTML>

Сервлеты

XMLReceiver.java

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import javax.servlet.ServletException;

import javax.naming.NamingException;

import java.io.IOException;

import java.io.PrintWriter;

public class XMLReceiver extends HttpServlet {

    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

        doPost( request, response );

    }

    public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {

        HttpSession session = request.getSession();

        try{

            MultiPartParser parser = new MultiPartParser(request);

            Part[] parts = parser.getAllParts();

            for( int i = 0; i < parts.length; i++ ){

                if( parts[i].isFile() ){

                    parser.proceedXml(parts[i]);

                }

            }

            response.setHeader( "cache-control", "no-store" );

            response.setHeader( "pragma", "no-cache" );

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