分享
 
 
 

JSP预编译工具

王朝java/jsp·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

---------------------------------------------------

Post Server Startup JSP File Compiler and Validator

---------------------------------------------------

This utility helps to

1. Simulate a precompilation of jsp's after the server has already started up.

This way, we do not have to wait for all the jsp's to be precompiled before starting up the server.

2. Test the validity of all the jsp's. If any jsp does not compile, a response code of 500 is returned. The tool lists that jsp, so it can be worked on.

The list of jsp targets to be precompiled must be supplied in a plain text file.

A sample is below:

#---------------------------------------------

/console/index.jsp

/console/standards/home.jsp

#---------------------------------------------

All the targets defined in there a hit sequentially, the response code monitored and such information relayed to the user.

Usage:

java TestJSPFiles <fName

If you specify no parameters, this help will be displayed

At least one parameter, the fileName should be specified

Below simulates the default argument list (if no parameters are passed in)jsp-pages.txt

If form based authentication is required, then send the username and parameters

System Properties, passed using the -D flag, are used to set the argument

list. They are listed below:

host the hostname or ip address of the machine port the port the server is listening on

debug If true, extra information like the actual output string is written to std error stream

If authentication is required to view some of the pages, the following will be required.

username The username to login as

password The password for that user formauthtarget The j_security_check target. By default, it is/j_security_check. It can be specified as the login page may vary.

Sample Usage is below:

java -Ddebug=false -Dhost=localhost -Dport=7701 -Dusername=system -Dpassword=system_password -Dformauthtarget=/console/login/j_security_check TestJSPFiles jsp-pages.txt

At the end, we tell you how many pages were OK (returned 200)

and how many were broken (including list of broken pages).

This will help you know which pages are broken immediately.

Any pages already precompiled will not precompile again.

Thus, there is no performance hit on running this script multiple times.

**** NOTE ****

The file passed should have the full path of pages to precompile

Example Scenario:

webapp context-path is /console

to precompile the jsp pages, index.jsp and standards/home.jsp in there

File should be as below

#---------------------------------------------

/console/index.jsp

/console/standards/home.jsp

#---------------------------------------------

Enjoy. - Ugorji ugorji.dick-nwoke@bea.com

// package weblogic.qa.taskmgr;

import java.util.*;

import java.io.*;

import java.net.*;

/**

* Precompiles all the jsp and tell us which are broken

* <xmpTo see Usage Information: java weblogic.qa.taskmgr.TestJSPFiles</xmp

* fName is the list of files with the paths of JSP files to precompile

* host and port are the server host and port respectively

*

* Currently, this is only geared towards FORM-based authenticated sites

*

* @author Ugorji Dick-Nwoke ugorji.dick-nwoke@bea.com

* @version 1.0, August 3, 2001

*/

public class TestJSPFiles

{

private static String HELP_MESSAGE = null;

public boolean DEBUG = false;

public List jspFiles;

public String host;

public int port;

public String username;

public String password;

public String cookieString;

public String formAuthTarget = "/j_security_check";

// set the HELP MESSAGE

static {

String lsep = System.getProperty ("line.separator");

HELP_MESSAGE =

"Usage: " + lsep +

"java [-Dhost=] [-Dport=] [-Dusername=] [-Dpassword=] [-Dformauthtarget=] TestJSPFiles <fName " + lsep +

"Defaults:" + lsep +

" -Dhost=localhost" + lsep +

" -Dport=80" + lsep +

" -Dusername=" + lsep +

" -Dpassword=" + lsep +

" -Dformauthtarget=/j_security_check" + lsep +

" File should be of the form below:" + lsep +

"#---------------------------------------------" + lsep +

"/console/index.jsp" + lsep +

"/console/standards/home.jsp" + lsep +

"#---------------------------------------------" + lsep +

"";

}

public String toString () {

String s = host + ":" + port + " [user/pass=" + username + "/" + password + "]";

return s;

}

public void run ()

throws Exception

{

cookieString = getCookieString ();

if (DEBUG) System.err.println (cookieString);

List badFiles = new ArrayList ();

List goodFiles = new ArrayList ();

int numGood = 0;

int numBad = 0;

int sz = jspFiles.size ();

for (int i = 0; i < sz; i++) {

String file = null;

try {

file = (String) jspFiles.get (i);

int respCode = getResponseCode (file);

if (respCode == 200) {

System.out.println ("Good: " + file + " --- Got RespCode " + respCode);

goodFiles.add (file);

numGood++;

}

else {

System.out.println ("Error: " + file + " --- Got RespCode " + respCode);

badFiles.add (file);

numBad++;

}

}

catch (Exception exc) {

System.out.println ("Error: " + file + " --- Got Exception " + exc);

badFiles.add (file);

numBad++;

}

if (DEBUG) {

System.err.println ("=============================================");

}

}

// output stats

System.out.println ("Good files: " + numGood);

System.out.println ("Bad files: " + numBad);

System.out.println ("---------------------------------------");

for (int i = 0; i < numBad; i++) {

System.out.println (badFiles.get (i) );

}

}

public int getResponseCode (String file)

throws Exception

{

int respCode = -1;

Socket s = new Socket (host, port);

PrintWriter out = new PrintWriter( new OutputStreamWriter( s.getOutputStream() ) );

String target = file + "?jsp_precompile=true";

out.print ("GET " + target + " HTTP/1.0" + "\r\n");

out.print ("Cookie: " + cookieString + "\r\n");

out.print ("Connection: close\r\n");

out.print ("Host: " + host + "\r\n");

out.print ("\r\n");

out.flush ();

BufferedReader buffreader = new BufferedReader( new InputStreamReader( s.getInputStream() ) );

String line = buffreader.readLine();

if( line != null ) {

StringTokenizer st = new StringTokenizer( line.trim() );

st.nextToken();

respCode = Integer.parseInt (st.nextToken());

}

while( (line = buffreader.readLine()) != null ) {

if( line.trim().length() == 0 ) break;

}

StringBuffer buf = new StringBuffer ();

while( (line = buffreader.readLine()) != null ) {

buf.append (line).append ("\n");

}

if (DEBUG) {

System.err.println (target);

System.err.println (respCode);

System.err.println (buf.toString () );

}

buffreader.close ();

out.close ();

s.close ();

return respCode;

}

public String getCookieString ()

throws Exception

{

String c

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有