Re: File download problem with JSP

2000-05-29 Thread D. J. Hagberg

The fundamental problem here is that a .doc file is a *byte* stream, not
a character-oriented text document.  You are seeing the effects of
character set translation and possibly truncation and probably some
problems due to null characters (though Java should not have any prob.
with this).

You need to make the junk.getDoc() return a byte[] array, then use
out.write(bytes) to output that back to the browser.  E.g.,

public byte[] getDoc() throws IOException {
File docFile = new File("myWord.doc");
InputStream in = new BufferedInputStream(
new FileInputStream(docFile) );
byte[] buf = new byte[docFile.length()];
in.read(buf);  // should verify #bytes read here.
return buf;
}

Next issue is that .jsp pages are designed for *text* output, not binary
output -- you should put your code in a Servlet.

-=- D. J.

Eric Butler wrote:
> The junk.getDoc() return a string that's just the reading of a file
> input stream.  The strange thing this is that if I create a file in the
> jsp and the write the results of getdoc to the file, the correct file is
> saved to disk.  Only when the result is spewed through http does it get
> hosed.
>
> I have also tried changing the getDoc to return an array of bytes and
> trying to morph that back into a valid file but I failed.
>
> Here's the code.  I've tried multiple permutations of commenting out
> and/or changing the first two lines.
>
> <%
> response.setHeader("Content-Disposition", "inline;
> filename=word.doc");
> response.setHeader( "Content-type", "binary/octect-stream");
> String myWordDoc = junk.getDoc();
> out.print ( myWordDoc );
> %>

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Tool for testing and debugging Javabeans?

2000-05-28 Thread D. J. Hagberg

Graham Cruickshanks wrote:
> Problem, It's a pain debuging runtime errors in these javabeans, by running
> them in jsp pages and getting output,
>
> Is there a easy way to debug and run javabeans before i use them in the jsp
> pages?

You might consider using one of the Java-based scripting languages such
as JPython (http://www.jpython.org/) or Jacl
(http://www.scriptics.com/java/ or the latest version at
http://www-users.cs.umn.edu/~dejong/tcl/tcljava/prerelease.html).

One nice feature of these scripting languages is that you can start up a
command-line interpreter and instantiate/modify/examine objects
on-the-fly.  Most of my experience is with Jacl, so I'll use it for
these examples.

jaclsh
% package require java
1.2.6
% set bean [java::new com.blah.MyBean]
MyBean@0F00
% $bean getName
Bubba
% $bean setName Vern
Vern

and so forth.  The real interesting part is when you notice that you
have both a full-fledged scripting language (not just a command-line
interpreted Java) and you have the full power of reflection --

% foreach method [java::info methods $bean] {
if {[llength $method] > 1} continue
if {[string match get* $method] || [string match is* $method]} {
puts "$method=[$bean $method]"
}
}

The above loops through all the methods in your bean, printing out the
value of all your getXXX and isXXX accessors.

The next step beyond the above is to build a set of test procedures and
regression tests for your beans.  If you download the Jacl source, you
will see that it comes with its own set of regression tests based on the
very compact tcltest framework.  You basically build little code
snippets like:

test testName-N.M "Description of test" {
bunch of code to set up objects and call methods
} {expected output of last statement in above code}

With this, you can start building up a set of test cases for both
positive (non-error) and cases where you expect errors to occur.  Every
time you find a bug in your code, you add a test case that reproduces
the bug -- BEFORE you even fix the bug.  Then after you fix the bug,
re-run the test suite to ensure you didn't break something else.

Hope this helps,

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: High points about Jason Hunters Servlet book?

2000-05-26 Thread D. J. Hagberg

Robert Nicholson wrote:
> Can somebody tell me what is consider the high point of Jasons book?

I think:
1) general introduction to the topic of servlets and how web protocols
work
2) demonstrations of dynamic image creation using AWT stuff and the ACME
GIF encoder
3) demonstration of file upload handling.

Downsides:
- dated -- covers only Servlet API 2.0 (maybe 2.1?)
- no information on JSP
- no discussion of web architectures or security

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Source Management

2000-05-23 Thread D. J. Hagberg

cvs or Concurrent Version System is a very powerful source code control
system, typically used mostly in Unix environments, but with ports to
various versions of Windows and MacOS.  A good starting point is:

http://www.loria.fr/~molli/cvs-index.html

And a document that discusses how to apply these principles to web
development is:

http://durak.org/cvswebsites/

We use it extensively to synchronize development between multiple
developers across the US on our jsp/html/image-based web sites and all
our java source and makefiles.

-=- D. J.

anderson wrote:
> Where I can take it ?
>
> Thank you so much
>
> anderson
>
> Carlos Latugaye wrote:
>
> > cvs
> >
> > -Original Message-
> > From: A mailing list about Java Server Pages specification and reference
> > [mailto:[EMAIL PROTECTED]]On Behalf Of anderson
> > Sent: Tuesday, May 23, 2000 7:42 PM
> > To: [EMAIL PROTECTED]
> > Subject: Source Management
> >
> > Anybody knows a software that manage source files to JSP ?
> >
> > Anderson

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: write method within response object

2000-05-23 Thread D. J. Hagberg

Claire Ryan wrote:
> what's the method to use for to write to HTTP output, i 've tried using
> response.write(String), but this doesn't work, any ideas?
> thanks in advance
> claire

Grab the JSP cheat-sheet at http://java.sun.com/products/jsp/ which will
tell you about all the implicit objects you may access in your scriptlet
code in JSP pages.  One of these is the "out" object, defined to be a
JspWriter which will have all sorts of operations for writing out text,
not that I would encourage this in JSP scriptlet code.  If you need
println and printing of non-String stuff, you should wrap that JspWriter
with a PrintWriter, as in:

<%  java.io.PrintWriter pw = new java.io.PrintWriter(out);
pw.println("...");
%>

On the other hand, if you are writing a servlet, you need to examine the
Servlet API specification, available for download at the same URL
above.  In there you will see a discussion of the
HttpServletResponse.getOutputStream() method, which again, can be
wrapped with a PrintWriter for text/html output:

public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html; charset=iso8859-1");
PrintWriter pw = new PrintWriter(response.getOutputStream());
pw.println("");
. . .
pw.flush();
}

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: JPEG/GIF Width

2000-05-22 Thread D. J. Hagberg

anderson wrote:
> Anyone knows how can I get the GIF or JPEG width ?

I have the beginnings of an open-sourced GIF decoder at:

http://millibits.com/djh/java/

Look at the implementation of readGIFIdentifier and
readGlobalImageDescriptor for a way to determine the image type and the
header info, including the width and height.

There was a discussion about getting similar information out of a JPEG
image header on news:comp.lang.java.programmer recently, though
considerably more complex as JPEGs can have a variable-length header.

A cheaper solution would be to store a simple .txt file with the same
name as all your .jpg and .gif files.  The text file would simply
contain the image width and height which can be read easily by all sorts
of applications.  A simple Unix script and the netpbm utilities could
create these .txt files pretty easily.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Memory for development machine running application server?

2000-05-18 Thread D. J. Hagberg

Robert Nicholson wrote:
> If I'm running an application server together with a database engine and
> will make use of a java compiler. What is the suggested amount of RAM needed
> for development?

Ummm...  As much as you can afford?

While some would argue that this post is rather off-topic, I will
concede that there is a small amount of JSP relevance here, as far as
what you need for a machine for development.

That said, this request is missing some *serious* information, like:

- what operating system do you plan to use?  Most OS' should be pretty
happy if you give them at least 64Mb.  I'm sure you would need to double
that for Win2K.

- what app server do you plan to use?  The vendors will be happy to
provide you with minimum or recommended system specs...

- what database engine do you plan to use?  Oracle is an incredible pig,
esp. Oracle 8i.  It needs at least 256Mb of its own to function
happily.  Sybase ASE 11.9 would be pretty happy with 64Mb for
development.  Not sure about ASE 12.

- Do you plan to use any GUI tools for Java development or just text
editors and javac?  GUI tools require considerable resources, esp. those
that are written in Java.

- What are the memory requirements for your application?  Are you
planning to cache lots of session or result set information in RAM?  If
so, you will need to use some profiling tools to plan how much memory
your JVM will need at runtime.  Plan on at least 64Mb per JVM.

I hope this gives you some starting points to consider...

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: CHECK-BOX

2000-05-16 Thread D. J. Hagberg

The call to request.getParameterValues("chkbox") should be returning
null, not throwing an exception.
Anyway, if you want to make sure you have a non-null array with 0 or
more elements, you could write a scriptlet like:

<%
String[] chkboxes;
if( request.getParameter("chkbox") == null ) {
chkboxes = new String[0];
} else {
chkboxes = request.getParameterValues("chkbox");
}
if( chkboxes.length > 0 ) {
// . . . do something . . .
}
%>

"Pillai, Arumugam" wrote:
> Hi there,
>
> When i call
>
> request.getParameterValues("chkbox")
> and if no chkbox is selected, its throwing a java.lang.NullPointerException
> error.How should i handle this.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Render HTML with images to PDF using JSP?

2000-05-15 Thread D. J. Hagberg

Steve Bang wrote:
> I'm searching for a way to take an HTML page with embedded GIFs and render
> it to a PDF file.  Is this possible using JSP?  Has anyone tackled this
> issue?  I'm new to JSP, but have been told it should be possible (I have my
> doubts).

Without writing your own page layout engine, no.

There are several free libraries for creating PDF from Java, but these
provide low-level primitives (draw a line, paint some text, etc.) mostly
equivalent to AWT Graphics (and in some cases Graphics2D) operations.

The KL Group (www.klgroup.com) has a commercial library for creation of
PDF from Java that has some page layout capabilities.

None of the above have a quick-and-dirty method of creating PDF from
HTML that I know of.

In the free software unix-y environment that are several apps that you
could execute -- we use HTMLDOC to go from HTML to PDF with moderate
success.  There is also html2ps which will take you to Postscript
output, and then Ghostscript's ps2pdf that will take you to PostScript
output.  You can use the freshmeat.net search facility to find most of
these.

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: curious. Getting database info

2000-05-09 Thread D. J. Hagberg

You will see a couple issues here:
[1] Database access can be agonizingly slow -- milliseconds and up

[2] In-Memory access can be very, very fast -- on the order of
microseconds.

[3] Memory space is finite, though most servers nowadays can hold up to
2Gb.  But you need to think about what you are going to do when your
cache size approaches some limit.  You will either need some decision
mechanism to toss things out of cache and some mechanism to decide when
to add things to cache.

[4] Caching breeds concurrency issues.  What do you do when the Customer
record you have cached in-memory is updated by someone else on the
server but in the meantime your web app has made changes to its copy?
You have both "detection" and "resolution" problems to solve here.

Problems [3] and [4] are the main headaches of highly-scalable systems
and become moreso (particularly [4]) when the load is distributed across
multiple servers.

-=- D. J.

Rick Reumann wrote:
> For example say you have various people in a database and have
> their name, phone number, address, etc. stored in there.
> Where I work we don't do the database select statements in the
> jsp pages but in seperate classes out on the server but obviously
> call them from the jsp pages.
>
>  I seem to think it's convenient then to create a vector of , for
> example, "people" objects and then iterate through the vector
> getting the information I need from each object..getPhoneNumber,
> getAddress, etc. Is this a good way to get this information from a
> database?
>
>  I'm also curious if it's worth an extra step of accessing the
> database first in order to get a row count that you could then use to
> give the vector a size? (will this even be worth it for a small
> database that maybe only has only 1000 rows?)
> Another method I've used is setting up an array of hashtables and
> then calling up each hash table and getting phone number,
> address, etc. that way. Is this better?

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Model 3 Architecture

2000-05-08 Thread D. J. Hagberg

This is certainly an interesting solution, and I can certainly see the
benefits when generating content for different display devices/browsers.

The primary question I have for Daniel and the other folks out there
using XSLT is -- what specific tools and techniques are you using for
this transform?  Is it:

- container-specific implementations of servlet chaining?
- jsp 1.1 taglets that transform their whole contained body?
- relying on cutting-edge browsers that actually do XSLT?
- some other mechanism like Cocoon?

-=- D. J.

Daniel Lopez wrote:
[ . . . ]
> .- The JSP page formats the result in XML, which is more easily
> understood by designers, can be used as documentation, and for which
> fake document sets are easily generated. The JSP can also determine "on
> the fly" which XSLT sheet will be used to generate the UI.
> .- The XSLT sheet transforms the XML into HTML, WML, PDF and result is
> sent to the client.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: jRUN AND JSP

2000-05-05 Thread D. J. Hagberg

Support questions about specific products should be directed to their
specific support forums.  In this case, you should visit
http://www.allaire.com/support/forums/index.cfm

Mohan Radhakrishnan wrote:
>Is it possible to configure JRun for JSP 1.0 without installing it
> again ?

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: How to write doGet/doPost method in JSP1.0?

2000-05-04 Thread D. J. Hagberg

VIKRANT JAIN wrote:
> can anybody reply to the above query please?
> unlike in the previous version of JSP1.0 there does not appear to be any
> page directive named "method" (or any other way) through which the
> scriptlet code may form a part of some method other than the default
> "service"

You can write methods by using the declaration tag:

<%!
public returntype methodname(paramtype1 param1...) {
// do something
// return something
}
%>

though I would certainly NOT try to override the jspService(...) method.

Note that this will not help you build re-usable code.  A better bet
would be to use a "Utility" bean or some other java class that you
write, perhaps with static methods so it doesn't need to be
instantiated.

Using beans and taglibs are the best way to structure a web app,
maximizing reusability.  You should strive to minimize the amount of
scriptlet/declaration/expression code in your .jsp pages.

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: images stored in database

2000-05-03 Thread D. J. Hagberg

One thing to remember is that JSP pages were designed for *text* output,
like text/plain, text/html, or text/xml.  Binary data should be output
by *Servlets*, not JSP's.

-=- D. J.

Antonio Jimenez wrote:
> i trying to view images stored in database
> the mime-type image/gif, image/bmp and image/tif(with plugin) work but image/jpg 
>don't work
> i am using JSWDK 1.0 on NT and the detail code is
> 
>
> OutputStream salida = response.getOutputStream();
>
> response.setContentType(rs.getString("MIMETYPE")) ;
> response.setContentLength(rs.getInt("TAMANO"));
>
> BufferedInputStream imageData = new 
>BufferedInputStream(rs.getBinaryStream("FOTO"));
> byte[] buf=new byte[4*1024];
>
> while ( (len = imageData.read(buf,0,buf.length)) != -1 ) {
> salida.write(buf);
> }
> salida.flush();

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: IPlanet reliability

2000-05-01 Thread D. J. Hagberg

Marco Fasoletti wrote:
> Thanks for the answer.
> How do you overcome the include and forward problem?

This appears to be a problem with *every* JSP 1.0 or 1.1 engine and part
of what the group working on the JSP 1.2 and Servlet 2.3 specs are
trying to fix.  Basically, if you  a page and then
something happens that throws an exception later in your document, the
errorPage mechanism will fail.  This is because the JSP engine must
flush() its output before the  starts and after it
finishes (correct me if I'm wrong here, folks).  No amount of buffering
will help since this is explicitly flushed.

The only workaround is to use the non-dynamic <%@include ...%> mechanism
and a large buffer that can hold the entire page output.

Perhaps another workaround would be to write your own 
tag that could do some sort of dynamic include that does not flush the
buffer.  I don't think anyone has done this yet.

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: JSP and IIS?

2000-04-13 Thread D. J. Hagberg

You may want to start with the links at the bottom of this email.  In
addition, there is a reasonably complete list of vendors at:



Look for those that say they are an Add-on Engine.  JRun and Resin are
both reasonable alternatives, with Resin being a bit speedier and having
better developer support (dynamic class reloading).

-=- D. J.

zoxx wrote:
> Does anybody know some plugin for IIS which enables JSP to run? Note that
> there is a lot of .asp on that IIS, and boss wants that both .asp and .jsp works
> on that IIS.
> Thanks in advance,
> zoxx
>
> P.S. I'm a newbee in JSP...
>
> Pozdrav,
> zoxx
> [EMAIL PROTECTED]
>
> ===
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: User Authentication

2000-04-13 Thread D. J. Hagberg

John Tangney wrote:
> On 4/12/00 7:13 PM, Vyacheslav Pedak at [EMAIL PROTECTED] wrote:
> > See Java Servlet API specification 2.2, you can download it from
> > http://java.sun.com/products/servlet/2.2/
>
> Thanks, but I *also* scoured the spec. What parts of the spec answer my
> question?

I don't know what the previous poster does, but you are correct that
there is no direct support for authentication in the Servlet spec.

What we do in our Model 1 apps (the simplest case) is rely on FORM-based
authentication, tracking a successful authentication via methods in a
bean that we store in the user's session.  Our "normal" pages have
something like:


<%  if( !userbean.isAuthenticated() ) {
response.sendRedirect("login.jsp");
}
%>

. . .

The isAuthenticated method of UserBean checks a boolean as to whether
the user successfully logged in or not.  If this flag is not set, we
redirect the user to the login page.  The login page looks something
like:


<% session.invalidate(); /* nuke any prior session information */ %>


Username: 

Password: 






When the user presses Submit, they are sent on to login2.jsp, which
performs the authentication check and, if successful, forwards on to the
main content page --

<@ page contentType="text/plain" buffer="16kb"
errorPage="loginError.jsp" %>


<%  // The above setProperty should have called setUser(...) and
setPassword(...)
// which will allow us to attempt authentication.  If we fail
authentication,
// the bean will throw an exception, which will bounce us over to
// the indicated errorPage above.

// If successful, this method will set the authenticated flag to
true.
// If not, it will set authenticated to false and throw an
exception.
userbean.authenticate();

// If we get this far, we must have succeeded.  Let the user in to
our app.
// Note that we use encodeURL here to handle cookie-less sessions.
response.sendRedirect(response.encodeURL("app_page1.jsp"));
%>

The app_page1.jsp would include the check shown at the top of this
email.  loginError.jsp would display the error message from the
"exception" implicit object and then give the user a link to bounce back
to login.jsp.

There are more efficient ways of implementing the above, particularly
ways that use jsp:forward rather than browser redirects.  I think the
above is the most straightforward to get folks started, though.

> >> And, more generally, what parts of
> >> the servlet API are accessible to my code when I'm using JSP?
> >>
> >
> > All API
> How?

First, you have access to the implicit objects defined in the JSP spec
(there is a cheat-sheet for download at http://java.sun.com/products/jsp
that lists these):

request   javax.servlet.http.HttpServletRequest
response  javax.servlet.http.HttpServletResponse
pageContext   javax.servlet.jsp.PageContext
session   javax.servlet.http.HttpSession
application   javax.servlet.ServletContext
out   javax.servlet.jsp.JspWriter
configjavax.servlet.ServletConfig
exception java.lang.Throwable

Second, you can access ANY Java class inside a scriptlet:

<%  com.blah.MyUtilityClass utils = new com.blah.MyUtilityClass();
utils.doSomething(request,response);
%>

as long as the class is accessible along your Servlet Engine's classpath
(configuring your servlet engine's classpath is vendor-specific --
consult your vendor documentation or visit one of the product-specific
support pages or email lists).

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: crypt() for Java...

2000-04-12 Thread D. J. Hagberg

Please, people!  crypt() has VERY LITTLE to do with JSP.  I would
suggest the comp.lang.java.programmer newsgroup and maybe, perhaps,
using a search engine -- google comes up with several relevant entries
with "crypt() for java"  In addition, a deja.com search turns up:
http://www.dynamic.net.au/christos/crypt/

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: localization

2000-04-11 Thread D. J. Hagberg

Arun Thomas wrote:
> Maybe my posting confused two issues  One of my issues had to do with
> ResourceBundles.  I hadn't been able to find any documentation in the
> JavaDocs
> which specified the encoding used for property resource bundles - it
> appears,
> from the info that Vyacheslav Pedak recently posted, that I didn't read it
> well enough

I believe property files need to use Unicode \u escapes for
non-7-bit-ASCII characters.  I believe the native2ascii utility will
help you by taking a property file in a charset like JIS, outputting the
same file with all the non-ASCII chars escaped.

> The second issue, however, was specific to JSP engines  I was trying to
> understand how the engines can determine the encoding used for storing the
> JSPs.
> In the case of JSPs, I think the it would becoming incredibly difficult to
> use
> if every non ISO-8859-1 character had to be unicode escaped  Do JSP
> engines
> use a default encoding for reading in JSP pages in order to interpret and
> compile
> them into servlets?

I believe this is specified in the JSP 1.0 and 1.1 specs.  Basically,
you specify the encoding of your JSP file *inside* the JSP file.  Your
very first directive in the file should be:

<%@ page contentType="text/html; iso8851-15" . . . %>

Your JSP engine *should* examine the encoding portion of the contentType
and interpret all bytes after that point as belonging to that character
set.  I'm pretty sure that JRun 2.3.3 builds >= 155 do this.  I don't
know about other engines.

I would be interested in others opinions on this part of the spec, esp.
those working on Tomcat or other implementations...

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Model 2, where to store and access the Database ConnectionPool

2000-04-10 Thread D. J. Hagberg

I believe most real-world ConnectionPool implementations get away with
their singleton-ness and supposedly garbage-collectable-ness by having a
background thread that keeps track of the static reference.  This
background thread is responsible for items like monitoring stats,
reducing the pool time at idle times, detecting database restarts and
initiating re-connections, etc.  Since this thread is still active with
a reference to the pool, the GC cannot collect it.

-=- D. J.

Sam Heisz wrote:
> On Fri, 7 Apr 2000, Sam Heisz wrote:
> sam>> What stops the instance from getting garbage collected? I read
> that
> sam>> starting version something-something-something, the garbage
> collector
> sam>> is more aggressive and will collect instances of objects that are
> only
> sam>> referred to by a member variable in the same class.
>
> Wes Biggs wrote:
> wes> Do you have a reference?  That would break tons of code out there,
> wes> including parts of the JDK itself that utilize the singleton
> pattern.
>
> Java In Practise: Design Styles And Idioms For Effective Java
> by Phil Bishop ,  Nigel Warren
> ISBN 0201360659
>
> page 131:
>
> "JDK 1.1.x specification added the feature of class unloading...
> where the only reference to the Singleton object is maintained within
> the Singleton class itself, the garbage collector, in its enthusiasm to
> dispose of any unused trash, may assume that the Singleton is
> unreachable because no other object or class holds a current reference
> to it and could quite legally garbage collect the object and unload the
> class...'

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Automagically convert your JSP 0.92 files to JSP 1.1

2000-04-04 Thread D. J. Hagberg

See the URL for a Tcl script that I wrote to help us with a lot of our
migration of JSP 0.92 to JSP 1.0.  It handles multi-line tags pretty
well, but does nothing with  tags except flag them.  It also
attempts to correct scriptlets that did not have terminating semicolons
(something you could get away with in the JRun version of JSP 0.9x).

http://millibits.com/djh/tcl/jsp2jsp.tcl.txt

It will run happily in Tcl 8.0 and newer, tested on Solaris, but should
run happily on Win32 platforms.  You can download Tcl binaries & source
from http://dev.scriptics.com/

Save the script as jsp2jsp.tcl and on Unix, make it executable.  Then
just call it with a single filename:

jsp2jsp.tcl my/original/file.jsp

It will save a copy of the original as my/original/file.jsp.orig and
then create a converted version.  Runs happily in a loop with the
bourne/bash/ksh for command:

for f in `find . -name '*.jsp' -print`; do
jsp2jsp.tcl $f
done

which converted our whole site in a matter of about 2 minutes, plus some
manual correction of LOOP tags etc.

-=- D. J.

Govind Seshadri wrote:
> Interested in learning about how to seamlessly convert your
> "legacy" JSP 0.92 files over to JSP 1.1?
>
> Check out our latest FAQ entry for complete details:
> http://www.jguru.com/jguru/faq/view.jsp?EID=32255

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: multiplication error

2000-04-04 Thread D. J. Hagberg

You will see this behavior in *any* implementation of *floating-point*
math.  By its very definition, operations in floating point imply a loss
of precision.

There are *lots* of websites that discuss the implications of this.
Some preliminary reading:

http://www.linuxsupportline.com/~billm/floating-point.html
http://www.validgh.com/goldberg/paper.pdf
http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html

Particularly the second link, "What every computer scientist should know
about floating point".

-=- D. J.

Sylvain Roche wrote:
> This may be a bit off topic, but I think it might concern any java
> developper.
>
> I'm using Blackdown's 1.2.2 JDK, but I remember having the same trouble in
> the past with others jdk too. I must be misdoing something :
> take two floats and multiply them : it works in most cases. Most cases ?
> for example
> (float)0.05 * (float)2179 = 108.950005 instead of 108.95
>
> in some cases, an operation like x / ( 1/y) works. In some others (including
> this one) it doesn't.
>
> The margin error is always less than 0.1.
>
> Is it a cast problem, or is it worse. (By the way, the same thing happens
> also in javascript both in IE and Netscape).
http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html
http://www.linuxsupportline.com/~billm/floating-point.html

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: More on Model 2 discussion - Interesting option to ActionClass approach.

2000-04-03 Thread D. J. Hagberg

See below for some comments

Personally, I think the issues you discuss below could be eliminated by
getting direct support for EJB's into the JSP spec, to be used as
regular JavaBeans are today.  I think some of the vendors are
implementing this sort of thing in their JSP 1.1 engines as custom tags,
which will give us some useful material upon which to build a
standard...

Kevin Duffey wrote:
> The one thing I didn't get an answer on from anyone yet is how to pass the
> same bean used by the forwarded JSP page, to the EJB, and get it back again.
> I am not quite clear on this. If I pass in an object, does it come back
> changed, or do I have to assign it for it to be changed? If so, do I need to
> create a new object (of the same bean instance) to reference the changed
> object, and so on.

I believe you should count on getting a different instance back from the
EJB, especially if the bean is being serialized and passed over the
network.  If that doesn't happen, there is very little overhead in
assigning a particular object reference back to itself:

// plop some values in a Java bean.
Bean mybean = new Bean();
mybean.setProp1(value1);
mybean.setProp2(value2);

// Send the bean off for processing, may get a new instance back
mybean = myEJB.doSomething(mybean);

> To elaborate on what I am trying to do, I was thinking that the adaptor
> (action) class' purpose is to get the request form data from the page/form
> submitted into a javabean, pass this bean as the serialized object parameter
> to the EJB, have the EJB use this data in whatever way needed, if it is,
> doing the logic and filling this bean with various data (maybe modifying
> existing properties, adding new data to empty properties to be used on the
> JSP page for display, etc). It then returns this same bean back to the
> adaptor class which then puts it in the request or session, and forwards to
> the JSP page so it can be displayed (if need be).

This is certainly one possible design methodology (I'll call it the
bean-as-cache pattern for now).  An alternative is the proxy pattern
which has been discussed here before.  I'm not sure whether one of these
is better than the other, but I too would like to hear comments from
others.

The primary issues for both design methodologies are handling
concurrency and caching.  You want to maximize caching to minimize
traffic between your EJB server and JSP/Servlet engine but at the same
time you do not want your web users to be viewing or updating data that
has been changed on the server.

The bean-as-cache pattern has the useful property of maximizing caching,
BUT you need to somehow handle concurrency.  This could ben an event
mechanism, where the bean receives an Invalidate event when something is
updated on the server.  Alternately, it could use a sequence number or
timestamp to detect that someone else has made an update on the server
when you attempt to submit your own change (an optimistic concurrency
model).  A third alternative is pessimistic concurrency, which locks
things on the server while being edited (NOT recommended for web apps
where the user can just browse away from your page).  Optimistic
concurrency is usually touted as having the best scalability, because
all conflict resolution is directed back at the user.

The proxy pattern has some really ugly overhead involved with hitting
the EJB server on every property get- or set-method.  This could really
only work well if the EJB server is running in the same process space as
your JSP/Servlet engine where the overhead is only a few method calls.
If you have to go across the network for every get/set method, your app
will fall to its knees.

> Another question which I believe pertains to this. Craig, you already said
> to use stateless ejb. So..if I have a multi-page form, in some cases the
> next form is built based on the previous forms data, do I store the data
> from all these forms on the web-server servlet-container HttpSession? Or is
> there some other mechanism for keeping state for a particular client on a
> multi-page form?

I belive Craig's intent was that the bean (or set of beans) should be
designed to carry enough information to model the real-world entity.
So, for instance, if you are modeling a CustomerOrder, you will want it
to contain LineItem's, ShippingInfo, PaymentInfo, etc.  When all items
are filled in, you would submit the whole CustomerOrder to an EJB
Session Bean for processing.

Personally, yes, I would store the CustomerOrder in the session until it
is complete.

The issue here is that the current JSP spec does not handle the
beans-contained-within-beans model very well.  You will have to do some
work with scriptlet tags to do this.

> Lastly, is it good, workable or bad design to use a single bean for multiple
> page forms data storage? I am not quite in the know if I should be using a
> javabean JUST for get/set operations to "model" the particular data the EJB
> will return and th

Re: Returning large resultsets

2000-04-03 Thread D. J. Hagberg

Sorry I may be a bit late in responding to this, but there is another
trade-off you could potentially make.

You could have a session-bound bean for a particular query that stores
the SQL (or enough info about the SQL Select to reconstruct it) and the
first and last rows displayed.  If the user moves to the next page, you
re-submit the query, tossing the first n rows, displaying the next p
rows and then cancel()'ing the query.

The downside of the above is the overhead of processing and tossing the
initial rows, which could put some strain on your network & server
The upside is that you minimize memory usage on the server.

-=- D. J.

"Donald E. Vandenbeld" wrote:
> Yes, the resultset beans that I use have a session scope so they are dealt
> with when the user either logs out or times out.  The problem is one of
> scalability.  There are a a few resultset beans that could potentially be
> quite large.  If you multiply this by the number of users on the system at
> any time, the memory usage could get out of hand.  Being that we are an
> underfunded educational institute, it's not likely we're going to get a
> memory upgrade for our server any time soon :-)
>
> My 'solution' right now looks something like this.  Each resultset bean is
> going to be associated with a specific webpage (jsp).  I will have a section
> of code at the beginning of every jsp in the site that checks the name of
> the current jsp page and deletes any resultset beans that are not associated
> with the current page.  I will just  this source at the
> beginning of each page which isn't that big an issue since I'm including
> lots of small files in every page anyway (to create formatting tables,
> headers, etc).
>
> Thanks to everyone who offered their thoughts on this.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: A Peculiar Problem with the HTTP Get method :- JSP

2000-03-29 Thread D. J. Hagberg

See below for comments...

Biju Nambisan wrote:
[ . . . ]
> A typical URL with parameter in this case is something like this
>
> http://localhost:/xyz.jsp? myselect_sk0=wh&myselect_macro0=weather
> &myselect_sk1=sp&myselect_macro1=sports &change=CHANGE
[ . . . ]
> parameter..When I am trying to print the values in the enumeration
> object it typically prints all the values in the following manner
>
> myselect_sk0(first checkbox element in the first row)
> myselect_sk1(first checkbox element in the second row)
> myselect_sk2(first checkbox element in the third row)
> ...so on
> change  (the button element )
> myselect_macro0(second checkbox element in the first row)
> myselect_macro1(second checkbox element in the second row)
> myselect_macro2(second checkbox element in the third row)
> ...so on
>
> If you have a look at the order of the parameter that are being passed
> they are in the order
> 
>myselect_sk0=wh&myselect_macro0=weather&myselect_sk1=sp&myselect_macro1=sports&change=CHANGE...
> ie first checkbox element in the first row,second checkbox element in
> the first row,first checkbox element in the second row,second checkbox
> element in the second row and so on...
>
> But on being stored in the enumeration they are getting stored in the
> way shown above..This is unuusal to me..

The fundamental issue is that getParameterNames() returns keys from a
HashTable (in all servlet engine implementations that I've seen).
Hastables, as any data structures textbook tells you, do NOT guarantee
the order of elements, and is most cases do really strange things with
the ordering.  The Servlet spec is not clear about this limitation, but
as your experiment has shown, if it does not explicitly state anything
about sorting, you cannot count on that.

Nor can you count on web browsers submitting form element values to you
in the order they were shown in the HTML page.  HTTP/HTML specifications
again make no guarantee about form element processing.

Your best bet is to name your form elements in a sortable order, use
getParameterNames() to put the parameter names into a data structure
that DOES guarantee sort order (see JDK 1.2's java.util.TreeMap) and
pluck the elements out of that.

[ . . . ]
> I would also like to know if there are any limitations of the no of
> characters that can be sent in a post/get methods..I believe the get
> method has a limit of 256 chars for it to behave properly ..Correct me
> if I am wrong..

I believe the practical limit of an HTTP GET is about 255 chars
*total*.  There is no upper bound on HTTP POST.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Using EJB in a JSP

2000-03-29 Thread D. J. Hagberg

This is one part of the "J2EE" strategy that the current specifications
leave unclear, so your questions are rather justified.

What I believe most people are doing is generating JavaBean
(non-Enterprise) classes that wrap up access to the EJB.  The primary
need for this is to provide the 0-argument constructor in the JavaBean
that would go through the typical methods of getting a reference to the
EJB.

This code should be possible to generate mechanically, rather than
typing it all in.  You might consider writing a simple tool that uses
Reflection to determine the methods, arguments, etc. for the EJB and
generate your JavaBean's .java file with wrapper methods and
constructor...

-=- D. J.

Nidhi Singhal wrote:
> I am in desperate need for this information. I have been trying to dig this
> out but...
> I have an EJB which is deployed on the Oracle 8i. Now I wish to use this EJB
> in my JSP page. Can somebody please help me with this problem.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: how to uplaoad a file??

2000-03-28 Thread D. J. Hagberg

You should take a look at jspFileUpload -- recently listed on the Java
Servlets Taverne page:

http://www.interpasnet.com/JSS/

Alternatively, as suggested elsewhere, Jason Hunter's File Upload
Servlet will do this.

Murtaza Ali wrote:
> i would like know how to upload the file to the my server. ia m stuck with
> this wfor quite a while noww I am usin gtomcat 3.0.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets



Re: Closing resultsets

2000-02-21 Thread D. J. Hagberg

This really belongs in a JDBC mailing list, not the JSP mailing list.
See below for answers, however.

Daniel Rvnnqvist wrote:
> I have a question about database connections. Should I or shouldn't I close
> all resultsets, statements after I've used them ? I've read that it's very
> important to do this because it may slow down your server if you don't close
> them and let the GC handle it (or timeout). But if I do this, close all my
> resultsets and statements, the server slow down and eventually hangs. If I
> don't it runs fine most of the time and just slows down one in hundredth of
> the times it did before.
> I recently changed from JDBC-ODBC bridge to another driver and then it works
> smoother but it still hangs from time to time.
>
> Could someone give me some hints about the following things:
> - When should I close my resultsets, statements and connections in
> comparrison to commit (I use auto commit off) and each other ?

You should commit/rollback after your transaction's statements have
closed.  A try/finally block facilitates this:

boolean completedOK = false;
Connection dbc = null;
Statement st = null;
try {
dbc =
ConnectionPool.checkout(ConnectionPool.MANUAL_COMMIT_MODE);
st = dbc.createStatement();
ResultSet rs = st.executeQuery(...);
while( rs.next() ) {
// process rows
}
rs.close();
st.executeUpdate();
completedOK = true;
}
finally {
if( st != null ) try {st.close()} catch(SQLException ignore) { }
if( dbc != null ) {
if( completedOK ) {
try {dbc.commit();} catch(SQLExeption ignore) { }
} else {
try {dbc.rollback();} catch(SQLException ignore) { }
}
ConnectionPool.checkin(dbc);
}
}


Since the finally block is mostly boilerplate code, you could implement
this as a static utility method.

> - Would a connection pool servlet solve this problem ? I've read that
> connection pooling is buildt in in JDBC 2.0.

A connection pool is essential when running in manual-commit mode to
maintain high performance (eliminating Connection establishment
overhead).  One can write a simple one in about a hundred lines.  Simply
implement a static method to check out and another one to check in.  In
our homegrown connection pool, we perform a .rollback() on any
Connections checked back in to eliminate "dangling" transactions.

> - What about thread safetyness and databases ?

Section A.1.6 in [Hamilton 1997], which is as close exists to a JDBC 1.x
spec says that "All operations on java.sql objects are required to be
multithread safe... a statement execution in one thread should not block
an execution in another thread ... two Statement objects on the same
connection can be executed concurrently [...] from the perspective of
the developer.  Some drivers will provide this full concurrency.  Others
may execute one statement and wait until it completes before sending the
next one.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: Capturing PrintStackTrace in Error.Jsp

2000-02-19 Thread D. J. Hagberg

"Loganathan, Kamalesh" wrote:
> I would like to capture the 'PrintStackTrace' from the ServletException and
> print it to the browser.  This is easy to implement in the Servlet. Anybody
> know how to implement this in a JSP page.


<%@ page isErrorPage="true" %>



<% exception.printStackTrace(new PrintWriter(out)); %>




===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: HTML from a bean?

2000-02-19 Thread D. J. Hagberg

A couple possibilities:
- returning an array of Strings (or Objects with appropriate toString
methods) works well if you know your result sets will be small and that
the creation of a bunch of temporary objects is not a huge deal.
- for larger or unknown-length result sets, you might consider providing
accessor methods so that the .jsp page can simply get the
java.sql.ResultSet, though you will need to wrap things in a try/finally
block inside the .jsp to ensure the underlying Statement is close()'d
before you return.
- As an alternative to providing direct access to the ResultSet, which
can be ugly for .jsp artist-types to program, you could wrap the
ResultSet with a kinder/gentler type of enumerated interface.  Same
problem with needing a try/finally block in the .jsp page to close
things up.

-=- D. J.

John Parrish wrote:
> What is the preferred method of generating HTML back to a JSP page from a
> bean? I was thinking about possibly returning a String array containing
> lines to be outputted and having JSP code loop and print. My scenario would
> be a bean that executes an SQL query and generates and HTML table with the
> results. I am very new to JSP so if I need prodding in a different
> direction, by all means prod! :) Regards

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



JSP 1.0 Specification Documentation Unclear

2000-02-14 Thread D. J. Hagberg

In section 2.13.2.1 of the JSP 1.0 specification where the syntax of
 is documented, the
following appears:

-- snip -
property

The name of the Bean property whose value you want to set.

If you set propertyName to * then the tag will iterate over the
current ServletRequest parameters, matching parameter names
and value type(s) to property names and setter method type(s), setting
each matched property to the value of the matching parameter. If a
parameter has a value of ""  , the corresponding property is not
modified.
-- snip -

I am confused by the last sentence in this spec (if a parameter has a
value of "" [which I presume to mean the empty string], the
corresponding property is not set).  This is apparently a changed
behavior between JRun 2.3.3 build 155 and build 157.

Does this rule only apply when property="*" or does it apply for ALL
specified property names?  In other words, to pick up empty form
elements do I simply need to break out my



to



. . .

or do I need to write special code to handle form elements that the user
could have deliberately (and reasonably) emptied out, such as the second
line of an address?

Thanks for any input...

-=- D. J.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: setting check boxes /URGENT HELP

2000-02-11 Thread D. J. Hagberg

Mistroni Marco wrote:
> can anyone tell me how can i, using getProperty, set the value of a
> check box to 'checked`? how is it possible to do that??
> please help me..
> thanx to all in advance

Using the ?: ternary operator inside an expression is what I do:

>

The expression

bean.isXXX() ? " CHECKED" : ""

evaluates to a string that is either " CHECKED" (note the leading space)
or the empty string, depending on whether the bean's XXX property is
true or not.

There is probably a better way to do this with custom tags in JSP 1.1,
but I'm stuck at JSP 1.0 for now...

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: JavaBeans vs Java bean

2000-02-10 Thread D. J. Hagberg

Please direct non-JSP questions to a more relevant discussion group if
you can...  The volume of non-JSP messages in this newsgroup is very
difficult to deal with.

That said, here is a reasonable place to start learning about JavaBeans:
http://java.sun.com/beans/FAQ.html

The parts that matter for JSP implementation are:
- class must implement zero-argument constructor
- accessor/mutator (get/set) methods must follow bean naming conventions
- needs to implement java.io.Serializable if you want to use it on a
sophisticated JSP server that does load
balancing/checkpointing/migration.

Rakesh Rajendran wrote:
> Can anybody tell what is the difference between JavaBeans and a Java Bean .
> It might look silly but frankly speaking I am confused.
> See..according to me any java class which can be re-used is a bean.  And
> same is true with JavaBeans.So I want to know what is there in JavaBeans
> which makes it different from a simple bean?
> Looking forward for ur help.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: Global Properties

2000-02-01 Thread D. J. Hagberg

You don't need to rely on the servlet engine for this, and you certainly
don't need to hard-code these values in any of your classes.  You should
implement a singleton design pattern "properties" class that loads
itself with information from a .properties file  -- a fairly simple
wrapper around java.util.PropertyResourceBundle.  You probably want to
provide some convenience methods that gets values as doubles, integers,
...  Typical usage would look like:

com.db.Configuration config = com.db.Configuration.getInstance();
String myServerName = config.getString("serverName");
int myServerPort = config.getInt("serverPort");

The relevant properties file would look like:

serverName=bubba
serverPort=5000


Rehman Habib wrote:
> For example, I work with a global website with multiple webservers and each has
> a connection to a local database.  It would be nice to define the TNS name as a
> property for each webserver which is then used by the class which performs the
> connection to the database.  If this isn't possible then I would have to hard
> code it into the class and have a different copy for each webserver - very nasty

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: New session in servlet included as image source

2000-01-30 Thread D. J. Hagberg

> David Galimberti wrote:
> [ . . . ] I am using the servlet as a source to an
> image as follows:
>
> 
>
> If I forward/redirect to my servlet from the JSP I have access to the
> session variables but if I use the servlet as a source to the image I
> do not (it actually wants to create a new session, i.e.
> request.getSession(false) returns null).

First of all, you need to use correct URL slashes (/).  Second, it's a
good idea to use response.encodeUrl(...) for *every* link on your page
that needs to maintain session.  This would include embedded 
tags that draw their data from servlets:

">

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: JSP included BeanLets and the processRequest method.

2000-01-21 Thread D. J. Hagberg

I think what you're missing are two fairly big fundamentals of JSP's:

beans != servlets
jsp's become servlets when compiled

Beans provide getXXX() and setXXX(...) methods to servlets and JSP's to
be able to maintain state.  Beans also provide non-set/get methods to do
useful actions like committing themselves to a database or performing
some sort of ugly calculation.

So, even if your bean has a processRequest(...) method, it will never
get called, uness you include something like the following after your
:

<% registerbean.processRequest(request); %>

Note that you can use the id from your useBean tag just like a variable
-- because it is.

I would argue, however, that having a processRequest method in your bean
is the wrong approach.  A better solution would be



This way, the JSP engine does all the work that your processRequest(...)
method would have to do.  It finds all parameters in the HTTP POST/GET
that match method names in your AMCreg.register class, does all the
necessary integer/double/boolean parsing, and calls the appropriate
setXXX(...) method to change the bean's state.  If you chose to write
this yourself, you're asking for an awful lot of work and maintenance
whenever you add another property to your bean.

-=- D. J.

Rob Fahey wrote:
> I am including the bean on the page as follows:
>
>  />
>
> I want to process all the data sent from a form on the previous page
> (thats quite a lot of data) in this beanlet. However, because it's a
> general purpose processing class, I don't know exactly what the fields
> in the POST/GET data will be... Hence, I have written a procedure into
> the beanlet which should process the request object, extract the data
> from it and store it in the Session object for later processing.
>
> public void processRequest(HttpServletRequest request) {
>  ... do stuff ...
> }
>
> Now, to my mind, based on my knowledge of general servlets, this process
> should be called as soon as I instantiate the beanlet on the page.
> However, as far as I can see, it isn't called at all... (I have debug
> lines in there which don't produce any output, which tells me that the
> method is never accessed).
>
> My question is, what am I doing wrong...? And am I approaching this in
> the right way in the first place? I have assumed all along that JSP
> beanlets have full access to the HttpServletRequest object... am I
> correct in this assumption?

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: Any JSP sites I can use as a reference?

2000-01-16 Thread D. J. Hagberg

Duffey Kevin wrote:
> I was wondering if anyone has JSP pages I can show my boss as a reference
> as to why we should be switching to the technology. He doesn't believe its

http://www.lightningstorm.com/

All our dynamic pages and displays are driven by JSP's and beans.  We
have had very few problems with our JRun/Netscape Enterprise/Solaris
deployment or our JRun/Apache/Linux development platforms.  Almost all
our problems have been with bugs in our own base Java classes and a few
interesting concurrency issues with our back-end database.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: Formatting email w/JSP

2000-01-11 Thread D. J. Hagberg

Louis Tribble wrote:
> I have a JSP/-based web app (Tomcat) that needs to format text messages
> and stow them away. It seems silly to use a third party template
> library when a JSP page would provide exactly the output stream I
> need, but I don't know how to capture that stream. Any ideas?

Well, you could make a URLConnection to http://localhost/jspname.jsp,
get the OutputStream and write that to a FileOutputStream.

If you have a lot of data parameters to pass to the .jsp that would not
fit neatly into the URL query string, you could use the O'Reilly
HttpMessage class to do a POST...

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: How does JSP handle non-persistant web connections andtransactions?

1999-12-14 Thread D. J. Hagberg

Keith Kwiatek wrote:
>
> If you are  using JSP to do web applications, how are you using JSP
>   to hand the fact that the web server connection to the database is
> non-persistant?

Well, before we talk about update issues, you should really consider
Connection pooling, whereby you keep a VM-wide set of connections to
your database and make them available by static methods in a
ConnectionPool (or similar) class.  This will remove the rather drastic
performance hit of opening a Connection to a database for every
transaction.

> For example, User "A" fetches a row for display in web page (db connection
> ends). At the same time user"B" fetches the same data for display in a web
> page (db connection ends). Then user "B" updates the row that user "A" is
> reading (db connection ends), then user "A" updates the row, thus
> overwritting user "B's" update)

This is a classic problem in client-server database design where the
client can change some data without directly updating the back-end
server (e.g., some client-side caching).  There are two classical ways
to detect/prevent the problem:

[1] Optimistic concurrency.  Add a column to your table that increments
every time an update is made.  Let's call it a `timestamp' (because
that's what Sybase calls theirs).  RDBMS' usually have a column type
with this behavior, though it's easy to implement yourself.  When the
client app selects one or more rows, it keeps the timestamp column
hidden from the user.  When the client app is ready to commit the
update, it must only perform the update if the row has remained
unchanged, ala:

UPDATE tabname SET c1=?,c2=?,c3=? WHERE id=? AND timestamp=TTT

replacing TTT with the hidden timestamp value from the SELECT.  You can
then check the number of rows affected which should == 1 on a successful
update, or 0 on a failed update.  You can then present the user with
options to re-do their changes based on the updated data, force their
data to be saved, or perform a more complex conflict resolution
operation.

[2] Pessimistic concurrency.  Add a column to your table that acts as a
lock.  When the user checks out a row for editing, that value gets
changed to a `locked' status.  When the user commits their changes, the
value gets changed to an `available' status.  During the time when the
row is locked, no other user can check-out the row for editing.

The problem with this technique, as you might guess, is that the client
can disappear at any time, leaving the row in a permanently locked
state.  This could be solved with appropriate use of timeouts, etc, but
starts to get complicated really fast.

Most people in high-transaction-volume operations tend to opt for [1],
as it puts the least strain on the server and relies on the probability
that `most of the time there will be no conflict'.  If you frequently
have the possibility of two users updating the same row, you should
really reconsider your database design.

Some vendors have Cached RowSet libraries that implement [1] and some of
which even implement basic conflict resolution for you, indicating which
columns are in conflict with the prior update.

> Also, how are you using JSP to handle updates to a row in which only SOME of
> the update fields change (instead of updating all of the fields in the
> rows)?

Well, you could keep an original copy of each column, then build an
UPDATE statement on-the-fly that only updates the changed columns, but
see my mention of conflict resolution for [1] above...

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: stored procedure

1999-12-09 Thread D. J. Hagberg

This is not a JSP question but rather a question on JDBC.  Books are
available from publishers Addison Wesley, O'Reilly, Prentice Hall,
etc...

Guilherme - PerConsult wrote:
> I`m trying to call a stored procedure using JSP... well, I have in my
> form a text box called "descricao", and my sp will insert the value
> written in my text box into the database.
>
> // "descricao" is the name of the text box
> String descricao2 = request.getParameter("descricao");
>
> // "InsereItem" is my stored procedure. I want to
> // insert the value that are in the text box called
> // "descricao" ...  I think that here is my mistake..
> CallableStatement cs = con.prepareCall("{call InsereItemAparencia
> "descricao2"}");

You need to use parentheses after the procedure name and put in question
mark placeholders.  The value it set using
cs.setX(placeholder_number,value) at a later point:

CallableStatement cs = con.prepareCall("{call
InsereItemAparencia(?)}");
cs.setString(1,descricao2);

The `1' means to replace the first question mark in the callable
statement with the given value.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: [Fwd: using ResultSet with JSP?]

1999-12-07 Thread D. J. Hagberg

Note this isn't a JSP question -- this is a rather fundamental question
about JDBC.  Please consult one of the books about JDBC, such as "JDBC
Database Access with Java" by Hamilton et. al.

Well, first you need to get the ResultSet object from the query.  If you
know the columns that will be returned, you could hard-code them.
Otherwise, you will need to get the ResultSetMetaData object from the
ResultSet and read the column names & data types.

Note that this code really belongs in a Bean or Servlet, not directly in
a .jsp page -- JSP pages should be mostly HTML content.

int row = 0;
int col = 0;
ResultSet rs = stmt.executeQuery(.);
ResultSetMetaData md = rs.getMetaData();
out.println("");
while( rs.next() ) {

// If this is the first row, use the metadata to print col headings
if( row == 0 ) {
out.print("");
for( col=1; col <= md.getColumnCount(); ++col ) {
out.print(""+md.getColumnLabel(col)+"");
}
out.println("");
}
++row;

// For each subsequent row, make the assumption that everything can
// be retrieved as a String.
out.print("");
for( col=1; col <= md.getColumnCount(); ++col ) {
out.print(""+rs.getString(col)+"");
}
out.println("");
}
out.println("");

// Make sure the JDBC objects can be reclaimed by the garbage collector.
md = null;
rs.close();
rs = null;
stmt.close();
stmt = null;

Guilherme - PerConsult wrote:
> <%
> String pesquisa = "select * from pessoa where nome = 'gui2'";
> stmt.executeQuery(pesquisa);
> %>
>
> fim
>
> 
> 
>
> On Control Panel I set my database as "teste" (the bridge). I have some
> data on the table "pessoa"  to make the query also..
>
> Well  the code is okay. But I don`t know how to print the result of
> this query on the screen in the JSP file...
>
> Can anybody help me???

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: JSP .92 vs 1

1999-12-06 Thread D. J. Hagberg

Cory L Hubert wrote:
> Right now I am using the .92 with JRUN.   Should I, can I upgrade to 1.0?

Yes.  Migrate now while (presumably) your code base is small.  At the
very least, avoid the LOOP, INCLUDEIF, and EXCLUDEIF tags in your jsp
0.92 pages as they are very difficult to mechanically convert to jsp
1.x.  The USEBEAN, SETFROMREQUEST, and SETONCREATE tags can be converted
mechanically as well as some page/errorpage directives.

Main reasons to switch:
- closer to XML compliance (I don't know what XML validators do with the
<%...%> directives and scriptlets) so you'll have better support from
visual XML page editors and validators.
- support for jsp 0.92 will probably be diminishing over the next year.
- (eventual) support for custom taglets.
- 1.0/1.1 will probably be the documented version in any upcoming books.
- *much* closer to jsp 1.1 compliance.

We're in the process of converting the http://lightningstorm.com site
from JSP 0.92 to 1.0.  The biggest pain has been with LOOP, INCLUDEIF,
and EXCLUDEIF tags.

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Value of vs <%= ... %> ?

1999-12-05 Thread D. J. Hagberg

A quick question for those of you in the know...

Are there rules or guidelines for when one should use:



versus when one should use:

<%= beanname.getPropname() %>

Personally, I think the latter is *much* cleaner inside a tag like the
following as you avoid the ugly sets of nested quotes (that mess up most
html validators).



===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html



Re: Connection Pool

1999-12-03 Thread D. J. Hagberg

Cory L Hubert wrote:
>
> Ok.  I am on a roll now.   I am trying to setup a Connection Pool.   I have
> a few samples.   But I don't know where to put it in my project.  Should I
> put it in the Beans?  Or should I just make one connectionpool jsp file and
> include it in all the pages?
>
> What is the best way?  I know this is an opened end question but, I'd like
> to hear a few suggestions.

We have also written a simple singleton ConnectionGenerator class that
has static poolCheckout(...) and poolCheckin(Connection) methods.  These
methods are used
inside our *bean* code whenever a db connection in needed.  This is done
because
you want to be sure to check the Connection back into a pool regardless
of whether
an exception occurred in your code or not, so you need a try/finally
combo.
We also use this combo to implement transaction rollback when
multi-statement
transactions are used.

For example:

boolean autoCommit = false;
boolean committed = false;
Connection c = ConnectionGenerator.poolCheckout();
Statement s = null;
try {
// do some stuff that could possibly throw an exception.
s = c.createStatement();
s.executeUpdate("UPDATE x SET q=5");
s.commit();
s.close();
committed = true;
s = null;
}
finally {
if( s != null ) try {s.close();} catch(SQLException ignore1) { }
if(!committed ) try {c.rollback();} catch(SQLException ignore2)
{ }
ConnectionGenerator.poolCheckin(c);
}

I really don't think you'd want to implement this sort of code in a
.jsp...

===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html