java文件
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Emaldome4 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 利用ServletContext对象加载src/config.properteis资源文件
ServletContext context = this.getServletContext();
InputStream is = context.getResourceAsStream("/res/config.properties");
Properties props = new Properties();
props.load(is);
// System.out.println(props.getProperty("email"));
int rows = Integer.parseInt(props.getProperty("row"));
int cols = Integer.parseInt(props.getProperty("col"));
System.out.println("row:" + props.getProperty("rows"));
System.out.println("col: " + props.getProperty("cols"));
PrintWriter pw = response.getWriter();
pw.write("<table border=‘1‘ align=‘center‘>");
for (int i = 0; i < rows; i++) {
if (i % 2 == 0) {// 偶数行
pw.write("<tr style=‘color:red‘>");
} else {// 奇数行
pw.write("<tr style=‘color:blue‘>");
}
for (int j = 0; j < cols; j++) {
pw.write("<td>");
pw.write("◇");
pw.write("</td>");
}
pw.write("</tr>");
}
pw.write("</table>");
}
}
原文地址:http://blog.51cto.com/357712148/2104581
时间: 2024-11-02 06:26:35