jsp预编译工具

js|编译

一个可以进行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 = "/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" + " ");
out.print ("Cookie: " + cookieString + " ");
out.print ("Connection: close ");
out.print ("Host: " + host + " ");
out.print (" ");
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 (" ");
}
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 ("POST " + target + " HTTP/1.0" + " ");
out.print ("Connection: close ");
out.print ("Host: " + host + " ");
out.print ("Content-type: application/x-www-form-urlencoded " );
String postString = "j_username=" + username + "&j_password=" + password;
out.print ("Content-length: " + postString.length() + " " );
out.print (" ");
out.print (postString + " " );
out.print (" ");
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( "set-cookie:" ) ) {
cookieLine = line.substring( "Set-Cookie:".length() ).trim();
int semicolon = cookieLine.indexOf( ";" );
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 + "?jsp_precompile=true";
URL url = new URL ("http", 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 = "jsp-pages.txt";
String tHost = "localhost";
int tPort = 80;
String tUser = null;
String tPass = null;
String tFormAuthTarget = "/j_security_check";
boolean tDebug = false;

String tmpstr = null;
if ( (tmpstr = System.getProperty ("host") ) != null)
tHost = tmpstr;
if ( (tmpstr = System.getProperty ("port") ) != null)
tPort = Integer.parseInt (tmpstr);
if ( (tmpstr = System.getProperty ("username") ) != null)
tUser = tmpstr;
if ( (tmpstr = System.getProperty ("password") ) != null)
tPass = tmpstr;
if ("true".equals (System.getProperty ("debug")) )
tDebug = true;
if ( (tmpstr = System.getProperty ("formauthtarget") ) != 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 ("#") )
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 ("file&: " + fName);
System.out.println ("TestJSPFiles: " + test);
test.run ();

}

}

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

# other stuff
/webapp1/ThankYou.jsp
/webapp2/ThankYou2.jsp
 

时间: 2024-11-06 01:28:51

jsp预编译工具的相关文章

jsp预编译问题

js|编译|问题 这个方法是到目前为止进行JSP预编译最方便的途径("flick-a-switch" 途径),他有许多指出来毫无意义的缺点.如果一个错误在JSP的编译期间或在部署(或重新部署) 的时候发生,Web 应用程序的预编译将会在例外处暂停.另外,如果在一个特定的Web应用程序里面有许多JSP文件的情况,declarative预编译显著的影响着部署时间,阻断部署直到所有的文件都被编译.对于大型的应用程序,当出现数以百计的JSP 文件以declarative预编译被执行的时候,这种

通过JSP预编译消除性能瓶颈

欢迎来到"管理角"这个版,新一期的月刊专栏专注于 WebLogic 服务器的管理.配置.处理和开发方面. 开辟这个专栏的目的是为了向大家介绍在使用WebLogic Sever时,能普遍用到的非J2EE开发方面的问题.开发者和管理者同样会发现这个专栏非常有价值,因为这些文章既适用于开发又适用于最终产品的应用.此外,它很大程度上利用了来自于该领域和工程实验室的经验,它提供了对实际问题的详细解答. JSP预编译的必要性 本文着眼于移除潜在的系统性能瓶颈,它通过解决一个最普通的问题??在服务器

Websphere在进行JSP预编译的时候提示无法分配内存

问题描述 您好我做了一个linux下的软件安装jar包,实现的是DB2和基于websphere的应用系统的安装以及其他相关配置的一个安装包,整体为一个jar包,但是在suse下用jar命令执行的时候会提示内存泄露,只有加上最大最小启动内存的参数设置后才可以运行出现swing对话框,但是从运行脚本到对话框出现有十几分钟,这是什么原因呢?而且在进行JSP预编译的时候不能进行,提示无法分配内存,因为我也刚刚接触不久所以不知道是哪方面的原因~~恳请指点下~ 解决方案 解决方案二:怎么都没有人来啊~~~~

把JSP预编译成class文件进行JSP文件的保护

js|编译 在Weblogic中发布Web Application工程时,为了保护JSP文件避免未经授权的访问和窥视,可以用weblogic.jspc把JSP文件precompile成为servlet文件,放到WEB-INF/classes目录下.基于Servlet的声明,WEB-INF不作为Web应用的公共文档树的一部分.因而,WEB-INF目录下的资源不是为客户直接服务的,这样就可以一定程度上保证JSP的安全. 具体的实现步骤如下(Weblogic for linux): 1.用weblog

通过JSP的预编译消除性能瓶颈

js|编译|性能 欢迎来到"管理角"这个版,新一期的月刊专栏专注于 WebLogic 服务器的管理.配置.处理和开发方面. 开辟这个专栏的目的是为了向大家介绍在使用WebLogic Sever时,能普遍用到的非J2EE开发方面的问题.开发者和管理者同样会发现这个专栏非常有价值,因为这些文章既适用于开发又适用于最终产品的应用.此外,它很大程度上利用了来自于该领域和工程实验室的经验,它提供了对实际问题的详细解答. JSP预编译的必要性 本月的文章着眼于移除潜在的系统性能瓶颈,它通过解决一个

通过JSP的预编译消除性能瓶颈_JSP编程

欢迎来到"管理角"这个版,新一期的月刊专栏专注于 WebLogic 服务器的管理.配置.处理和开发方面.<?XML:NAMESPACE PREFIX = O /> 开辟这个专栏的目的是为了向大家介绍在使用WebLogic Sever时,能普遍用到的非J2EE开发方面的问题.开发者和管理者同样会发现这个专栏非常有价值,因为这些文章既适用于开发又适用于最终产品的应用.此外,它很大程度上利用了来自于该领域和工程实验室的经验,它提供了对实际问题的详细解答. JSP预编译的必要性 本

服务器-更新ASP.NET网站时:未预编译文件“XXXX.ASPX”,因此不能请求该文件

问题描述 更新ASP.NET网站时:未预编译文件"XXXX.ASPX",因此不能请求该文件 原网站是把.CS文件预编译成dll,和.aspx文件等预编译成 .compiled文件+一个空的aspx页面(这是个61B的空文件,打开就一句话"这是预编译工具生成的标记文件,不应被删除!"). 好了,介绍好这些后.我源码更新了其中某些页面,包括一些CS文件,用同样的放是编译,挑出了我改动的7个页面的.compiled文件,以及其对应的7个dll.如何对应的呢,是打开.com

Jetbrick-template 1.2.0 发布,新增预编译功能

Jetbrick-template-1.2.0 发布,新增预编译功能. 具体更新内容如下: 功能更新 [新增] #38 增加默认的 #tag cache() 实现模板局部缓存功能 [新增] #49 增加模板预编译工具/选项 [新增] #54 增加安全管理器:黑白名单 [新增] #62 在 Web 环境中使用 jetx 时候,建议增加一个隐藏变量 [新增] #63 对 Array/List/Map 的 [] 访问,增加安全调用 [新增] #64 Spell error in JetAnnoatio

jsp往数据库写数据预编译的时候出现乱码

问题描述 jsp往数据库写数据预编译的时候出现乱码 今天写了个注册系统,可是我往数据库里写数据时出现"???"乱码,但是预编译之前 的值都是正常的,jsp页面是utf-8的,servlet也没有问题,数据库也是utf-8的,只是使用 PreparedStatement就出现乱码了 解决方案 看看数据库定义的字段是什么,用nvarchar看看 解决方案二: 可能是 设置datasource 的driver 没有指定编码~ 路径查查看