SSD1的Pratical-quiz-6答案

本文介绍了一个名为 OOGallery 的 Java 类,该类继承自 HttpServlet,用于处理 HTTP POST 请求,通过获取用户提交的主题和背景图片参数来创建 HTML 页面并显示两幅主题图片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

{声明:不得转载}
当时好像使用DJ Java Decompiler反编译iCarnegie给的.class文件,然后抄了一点代码,我给出的代码好像不能编译,各位仔细咯
/**
 *  Author:   
 *  Date:    05-09
 *  Description: exercise6
 */
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class OOGallery extends HttpServlet {
    public void doPost(HttpServletRequest request,
                        HttpServletResponse response)
                        throws ServletException, IOException {

        /**
         *  Indicate the content type (for example, text/html),
         *  being returned by the response
         */
        /* Add your code here */

        response.setContentType("text/html");

        /**
         *     Retrieve an output stream to use to send data to the client
         */
        /* Add your code here */

        PrintWriter out = response.getWriter();
        /**
         *     Get the user input from the form
         */
        /* Add your code here */
        String ThemePicture1 = request.getParameter("theme")+"One";
        String ThemePicture2 = request.getParameter("theme")+"Two";
        String BackgroundImage = "/"+request.getParameter("bgrnd")+".gif";
        String Bgcolor="#FFF8DC";


        /**
         *     Create an instance of the HtmlPage class
         */
        /* Add your code here */
        HtmlPage htmlPage = new HtmlPage();
       
        /**
         *     Create an instance of the HtmlImage class for the first image
         */
        /* Add your code here */
        HtmlImage htmlImage1 = new HtmlImage("/" + ThemePicture1 + ".jpg", ThemePicture1);

        /**
         *     Create an instance of the HtmlImage class for the second image
         */
        /* Add your code here */
        HtmlImage htmlImage2 = new HtmlImage("/" + ThemePicture2 + ".jpg", ThemePicture2);

        /**
         *     Set the attributes of the HtmlPage object
         */
        /* Add your code here */
        htmlPage.setTitle("OOGalleryPage using HtmlPage and HtmlImage classes");
        htmlPage.setBackgroundImage(BackgroundImage);
    htmlPage.setBackgroundColor("Bgcolor");


        /**
         *     Add the images
         */
        /* Add your code here */
        String picture1=htmlImage1.buildHtml();
        String picture2=htmlImage2.buildHtml();
        htmlPage.addText(picture1);
        htmlPage.addText("<BR>");
        htmlPage.addText("<BR>");
        htmlPage.addText(picture2);

        /**
         *     Finish building the Web page
         */
        /* Add your code here */
        out.println(htmlPage.buildHtml());

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值