选择显示字体大小

jsp预编译工具

一个可以进行jsp预编译工作的程序. 下面是read.me 以及 java 源程序.
author: ugorji dick-nwoke ugorji.dick-nwoke@bea.com
date: jan 16. 2002

---------------------------------------------------
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
* <xmp>to 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 = &quot;/j_security_check&quot;;

// set the help message
static {
string lsep = system.getproperty (&quot;line.separator&quot;);
help_message =
&quot;usage: &quot; + lsep +
&quot;java [-dhost=] [-dport=] [-dusername=] [-dpassword=] [-dformauthtarget=] testjspfiles <fname> &quot; + lsep +
&quot;defaults:&quot; + lsep +
&quot; -dhost=localhost&quot; + lsep +
&quot; -dport=80&quot; + lsep +
&quot; -dusername=&quot; + lsep +
&quot; -dpassword=&quot; + lsep +
&quot; -dformauthtarget=/j_security_check&quot; + lsep +
&quot; file should be of the form below:&quot; + lsep +
&quot;#---------------------------------------------&quot; + lsep +
&quot;/console/index.jsp&quot; + lsep +
&quot;/console/standards/home.jsp&quot; + lsep +
&quot;#---------------------------------------------&quot; + lsep +
&quot;&quot;;
}

public string tostring () {
string s = host + &quot;:&quot; + port + &quot; [user/pass=&quot; + username + &quot;/&quot; + password + &quot;]&quot;;
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 (&quot;good: &quot; + file + &quot; --- got respcode &quot; + respcode);
goodfiles.add (file);
numgood++;
}
else {
system.out.println (&quot;error: &quot; + file + &quot; --- got respcode &quot; + respcode);
badfiles.add (file);
numbad++;
}
}
catch (exception exc) {
system.out.println (&quot;error: &quot; + file + &quot; --- got exception &quot; + exc);
badfiles.add (file);
numbad++;
}
if (debug) {
system.err.println (&quot;=============================================&quot;);
}
}

// output stats
system.out.println (&quot;good files: &quot; + numgood);
system.out.println (&quot;bad files: &quot; + numbad);
system.out.println (&quot;---------------------------------------&quot;);
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 + &quot;?jsp_precompile=true&quot;;
out.print (&quot;get &quot; + target + &quot; http/1.0&quot; + &quot;\r\n&quot;);
out.print (&quot;cookie: &quot; + cookiestring + &quot;\r\n&quot;);
out.print (&quot;connection: close\r\n&quot;);
out.print (&quot;host: &quot; + host + &quot;\r\n&quot;);
out.print (&quot;\r\n&quot;);
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 (&quot;\n&quot;);
}
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 cookieline = null;
string c = null;
socket s = new socket (host, port);
printwriter out = new printwriter( new outputstreamwriter( s.getoutputstream() ) );
string target = formauthtarget;
// out = new printwriter (system.out, true);
out.print (&quot;post &quot; + target + &quot; http/1.0&quot; + &quot;\r\n&quot;);
out.print (&quot;connection: close\r\n&quot;);
out.print (&quot;host: &quot; + host + &quot;\r\n&quot;);
out.print (&quot;content-type: application/x-www-form-urlencoded\r\n&quot; );
string poststring = &quot;j_username=&quot; + username + &quot;&j_password=&quot; + password;
out.print (&quot;content-length: &quot; + poststring.length() + &quot;\r\n&quot; );
out.print (&quot;\r\n&quot;);
out.print (poststring + &quot;\r\n&quot; );
out.print (&quot;\r\n&quot;);
out.flush ();
bufferedreader buffreader = new bufferedreader( new inputstreamreader( s.getinputstream() ) );
string line = null;
while( (line = buffreader.readline()) != null ) {
if (debug) system.err.println (line);
if( line.trim().length() == 0 ) break;
if( line.tolowercase().startswith( &quot;set-cookie:&quot; ) ) {
cookieline = line.substring( &quot;set-cookie:&quot;.length() ).trim();
int semicolon = cookieline.indexof( &quot;;&quot; );
if( semicolon != -1 ) {
cookieline = cookieline.substring( 0, semicolon ).trim();
}
break;
}
}
buffreader.close ();
out.close ();
s.close ();
return cookieline;
}

public int getresponsecode0 (string file)
throws exception
{
httpurlconnection urlconn = null;
try {
string target = file + &quot;?jsp_precompile=true&quot;;
url url = new url (&quot;http&quot;, host, port, target);
urlconn = (httpurlconnection) url.openconnection ();
urlconn.connect ();
// inputstream is = urlconn.getinputstream ();
// while ( is.read (b) != -1 ) { }
int respcode = urlconn.getresponsecode ();
return respcode;
}
finally {
try { if (urlconn != null) urlconn.disconnect (); }
catch (exception exc2) { }
}
}

/** <xmp>usage: java weblogic.qa.taskmgr.testjspfiles <fname> <host> <port> </xmp> */
public static void main (string[] args)
throws exception
{
if (args.length == 0) {
system.out.println (help_message);
system.exit (0);
}

string fname = &quot;jsp-pages.txt&quot;;
string thost = &quot;localhost&quot;;
int tport = 80;
string tuser = null;
string tpass = null;
string tformauthtarget = &quot;/j_security_check&quot;;
boolean tdebug = false;

string tmpstr = null;
if ( (tmpstr = system.getproperty (&quot;host&quot;) ) != null)
thost = tmpstr;
if ( (tmpstr = system.getproperty (&quot;port&quot;) ) != null)
tport = integer.parseint (tmpstr);
if ( (tmpstr = system.getproperty (&quot;username&quot;) ) != null)
tuser = tmpstr;
if ( (tmpstr = system.getproperty (&quot;password&quot;) ) != null)
tpass = tmpstr;
if (&quot;true&quot;.equals (system.getproperty (&quot;debug&quot;)) )
tdebug = true;
if ( (tmpstr = system.getproperty (&quot;formauthtarget&quot;) ) != null)
tformauthtarget = tmpstr;

if (args.length > 0)
fname = args [0];
if (args.length > 1)
thost = args [1];
if (args.length > 2)
tport = integer.parseint (args [2]);
if (args.length > 3)
tuser = args [3];
if (args.length > 4)
tpass = args [4];

filereader fr = new filereader (fname);
bufferedreader br = new bufferedreader (fr);
list files = new arraylist ();
string line = null;
while ( (line = br.readline () ) != null ) {
line = line.trim ();
if (line.length() == 0 line.startswith (&quot;#&quot;) )
continue;
files.add (line);
}
fr.close ();
br.close ();

testjspfiles test = new testjspfiles ();
test.host = thost;
test.port = tport;
test.jspfiles = files;
test.username = tuser;
test.password = tpass;
test.formauthtarget = tformauthtarget;
test.debug = tdebug;

system.out.println (&quot;file: &quot; + fname);
system.out.println (&quot;testjspfiles: &quot; + test);
test.run ();

}


}

# top level files
/console/index.jsp
/console/help.jsp

# other stuff
/webapp1/thankyou.jsp
/webapp2/thankyou2.jsp


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons