[英]How to simulate 120 concurrent users of a web application with real conditions?
[英]Simulate a real web page with jsp
我想要一个真实的网页。 在网页加载时服务器上的图像变慢。 我下载了我在eclipse tomcat服务器上工作的网站。 显然图像加载过去。 我希望他们慢。
我试过Thread.sleep()
<div style="width:100px; height:75px; float:left" id="rsim"><a href="inc/6.html"><img border="0"
width="100" height="75" **<% Thread.sleep(2000); %>src="inc/images/bo.jpg"** /></a></div>
<div style="width:100px; height:75px; float:left" id="rsim"><a href="inc/4.html"><img border="0" width="100" height="75" **<% Thread.sleep(2000); %> src="inc/images/la1.jpg"** /></a></div>
但它等待整个网站4秒钟,然后加载网站非常快。
我会使用过滤器:
package mypackage;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class WaitFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
// nothing
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// ignore
}
chain.doFilter(request, response);
}
public void destroy() {
// nothing
}
}
然后,在您的web.xml中:
...
<filter>
<filter-name>WaitFilter</filter-name>
<filter-class>mypackage.WaitFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>WaitFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.