JAVA - 将用户输入打印到 HTML
JAVA - Printing user input into HTML
我想使用 Java 获取用户输入并以 index.html
形式打印。用户输入在数组列表中。通过查看代码,您可以看出它将从 #nbOfPieces
次打印 HTML 次。如何打印 arraylist 中的单个项目并且只打印一次 html 代码?
for (int i = 0;i < nbOfPieces ;i++ ) {
pw.println(
"<html>\n" +
"<head>\n" +
" <title>Maria Shop</title>\n" +
" <link rel=\"stylesheet\" href=\"style.css\">\n" +
"</head>\n" +
"<body>\n" +
"<center>\n" +
"<section id=\"portfolio\">\n" +
" <h1>MARIA TEST</h1>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
"</section>\n" +
"</center>\n" +
"</body>\n" +
"</html>"
);
}
只需将要打印的内容分成三份,如下所示:
pw.println(
"<html>\n" +
"<head>\n" +
" <title>Maria Shop</title>\n" +
" <link rel=\"stylesheet\" href=\"style.css\">\n" +
"</head>\n" +
"<body>\n" +
"<center>\n" +
"<section id=\"portfolio\">\n" +
" <h1>MARIA TEST</h1>"
);
//Repeated sectection
for (int i = 0;i < nbOfPieces ;i++ ) {
pw.println(
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>"
);
}
pw.println(
"</section>\n" +
"</center>\n" +
"</body>\n" +
"</html>"
);
我想使用 Java 获取用户输入并以 index.html
形式打印。用户输入在数组列表中。通过查看代码,您可以看出它将从 #nbOfPieces
次打印 HTML 次。如何打印 arraylist 中的单个项目并且只打印一次 html 代码?
for (int i = 0;i < nbOfPieces ;i++ ) {
pw.println(
"<html>\n" +
"<head>\n" +
" <title>Maria Shop</title>\n" +
" <link rel=\"stylesheet\" href=\"style.css\">\n" +
"</head>\n" +
"<body>\n" +
"<center>\n" +
"<section id=\"portfolio\">\n" +
" <h1>MARIA TEST</h1>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
"</section>\n" +
"</center>\n" +
"</body>\n" +
"</html>"
);
}
只需将要打印的内容分成三份,如下所示:
pw.println(
"<html>\n" +
"<head>\n" +
" <title>Maria Shop</title>\n" +
" <link rel=\"stylesheet\" href=\"style.css\">\n" +
"</head>\n" +
"<body>\n" +
"<center>\n" +
"<section id=\"portfolio\">\n" +
" <h1>MARIA TEST</h1>"
);
//Repeated sectection
for (int i = 0;i < nbOfPieces ;i++ ) {
pw.println(
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>\n" +
" <div class=\"img-box\">\n" +
" <a href=" + links.get(i) + "><img src=\"./img/"+subImg.get(i)+"\" alt=\"CPU image\"></a>\n" +
" </div>"
);
}
pw.println(
"</section>\n" +
"</center>\n" +
"</body>\n" +
"</html>"
);