| <html> <head> <title>タグの属性を編集しよう!</title> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> </head> <body bgcolor="#FFFFFF" text="#000000"> |
//標準API
import java.io.*;
//ServletAPI
import javax.servlet.*;
import javax.servlet.http.*;
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.ParserFactory;
import jp.kuro.meteor.Parser;
import jp.kuro.meteor.printer.HttpPrinter;
public class AttrServlet1 extends HttpServlet {
ParserFactory pf;
public void init(ServletConfig sConf) throws ServletException {
//"attr.html"の絶対パスを取得する
ServletContext sc = sConf.getServletContext();
String path = sc.getRealPath("/WEB-INF/html/");
//パーサファクトリオブジェクトを生成し、"attr.html"を読み込む
pf = new ParserFactory(path);
pf.parser(Parser.HTML, "attr1.html", "Shift_JIS");;
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
//Parserオブジェクトを取得する
Parser xt = pf.parser("attr1");
//"Hello,World"を赤くします。
Element tag = xt.element("font", "id", "hello");
tag.attribute("color", "#FF0000");
//文字列のサイズを変更します
tag.attribute("size", "4");
//反映する
xt.flush();
//HTTP出力する
HttpPrinter prt = new HttpPrinter(res);
prt.print(xt);
}
}
|
| <html> <head> <title>タグの属性を編集しよう!</title> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> </head> <body bgcolor="#FFFFFF" text="#000000"> |
//標準API
import java.io.*;
//ServletAPI
import javax.servlet.*;
import javax.servlet.http.*;
//Kuro API
import jp.kuro.meteor.*;
import jp.kuro.meteor.printer.HttpPrinter;
public class AttrServlet2 extends HttpServlet {
ParserFactory pf;
public void init(ServletConfig sConf) throws ServletException {
//"attr.html"の絶対パスを取得する
ServletContext sc = sConf.getServletContext();
String path = sc.getRealPath("/WEB-INF/html/");
//パーサファクトリオブジェクトを生成し、"attr2.html"を読み込む
pf = new ParserFactory(path);
pf.parser(Parser.HTML, "attr2.html", "Shift_JIS");
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
//Parserオブジェクトを取得する
Parser xt = pf.parser("attr2");
//fontタグのcolor属性を消します。
Element tag = xt.element("font", "id", "hello");
xt.removeAttribute(tag, "color");
//反映する
xt.flush();
//HTTP出力する
HttpPrinter prt = new HttpPrinter(res);
prt.print(xt);
}
}
|