servlet 课堂小测试

1.使用servlet创建一百个连接
2.创建一个表格,基行和偶行颜色不一样
3.添加图片

首先我们

附上java代码:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.imageio.ImageIO;

public class Yemian	extends GenericServlet{

	public void service(ServletRequest reques,ServletResponse response)
	throws ServletException,IOException{
		PrintWriter out = response.getWriter();
		out.println("<html><head><title>lianjie</title></head><body>");
		for(int i = 0;i<100;i++){
			out.println("<table border='4'>");
			if(i%2==0){
				out.println("<tr><td bgcolor='red'><a href='http://www.baidu.com' target='_blank'>baidu</a></td><td>111</td><td>222</td></tr>");
			}else{
				out.println("<tr><td bgcolor='blue'><a href='http://www.baidu.com' target='_blank'>baidu</a></td><td>111</td><td>222</td></tr>");
			}
			
			
			out.println("</table>");
		}
		for(int j = 0;j<10;j++){
			out.println("<img src='1.jpg'>");
		}
		out.println("</body>");
		out.println("</html>");
	}
}


附上XML代码:

<web-app>
<servlet>
	<servlet-name>yemian</servlet-name>
	<servlet-class>        //此名字要与类名对应
		Yemian
	</servlet-class>
</servlet>

<servlet-mapping>
	<servlet-name>yemian</servlet-name>
	<url-pattern>/hello123</url-pattern>        //伪链接
</servlet-mapping>
</web-app>

效果图:

posted @ 2021-03-29 14:15  网抑云黑胶SVIP用户  阅读(78)  评论(0编辑  收藏  举报