A couple of issues with JSP - Db and Extends

I have a couple of questions relating JSP (directly or indirectly)

1. I have typical requirement in the presentation wherein the JSP has to display all the 30,000 records from the dB in one page. How can I do it? (I don抰 want to use pagination); (Real Problem is: the time required to fetch the data from the database is more than the session time out i.e., while the resultset is building up the rows, the JSP session terminates.)

2. How would I extend a jsp page? Like if I write a class in a jsp page using scriptlet and writing methods in it. If I want toextend this class to another jsp page, how would it be possible?

3. What part of code of jsp goes into the servlet? For example a servlet has init, service and destroy method. If I write a jsp declaration, where does this part of code goes into a servlet converted jsp. (into init(), service() or destroy() ?)

Please regret if I sounded stupid with these questions. But I wanted to clarify them. Any hint or explaination would be of a great help.

Thanks so much in very advance.

Rk.

[1092 byte] By [passion_for_javaa] at [2007-11-27 6:19:58]
# 1
If my boss ever orders me to complete such a task I'll quit this job immediately.
citcrua at 2007-7-12 17:35:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

1 - Stupid requirement. People want a responsive system, not a 1/2 hour page load. Why don't you want to use pagination?

Does this data change often? If it HAS to be a 30,000 record page could you pre-generate it, and have the user download a static file?

What does the query look like for retrieving this data? Is it efficient? Could you maybe rewrite the query? Add an index in the database to speed things up?

2 - You can't extend JSP pages. If you want to write sharable code with methods etc I would suggest putting it into a java class, and calling methods on that class. In any case Scriptlet code in a JSP is no longer considered best practice.

3 - Anything that you write between <%! declaration tags %> gets imported as declarations - eg methods, class attributes etc.

Anything between <% scriptlet tags %> gets imported as part of the jsp_service() method that gets invoked on each request.

evnafetsa at 2007-7-12 17:35:01 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

1. increase the timeout time, or else you are stuck. You could try improving the query speed with a database index, but you can never be sure that it won't fail with 40000 records.

2. you absolutely do not want to do this

3. you can find the servlet code on disk after you run the JSP for the first time. For example for tomcat you can find the generated servlets in the "work" subdirectory.

gimbal2a at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

1 - Stupid requirement

Yes! Agreed. But let me tell you this was the question from one of the most renowned company's interview.

3 - Anything between <% scriptlet tags %> gets imported as part of the jsp_service() method that gets invoked on each request

In that case what if, I declare a method in the scriptlet tag. Does the method declaration also goes into the jsp_service(). [ a method declaration inside another method?]

passion_for_javaa at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
for eg. If I had to declare a method should be 1. this way ?<% public void method1(); %>2. or this way<%! public void method1(); %>And where does this method goes into which method of the servlet?
passion_for_javaa at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Stupid requirements + inexperienced developer = big problems.I suggest you to talk about this with your boss or just to look for another employer who want to invest in your knowledge by supplying books and courses.
BalusCa at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Well, lets keep things which are beyond the scope of this forum. This question was brought to my notice by my colleague who has attended an interview in a top MNC!! And he was asked this so called stupid question.

(out of my curiosity) I just wanted to know (technically, forget whether it is a good programming practice or not) is it possible to write method declaration/prototype in the scriptlet tag of a JSP. And if possible, where does this method declaration appear in the servlet?

Any one who can answer (or feel like that this question deserves one), request you to post it. And request you not to put any comment which is irrelevant to the question.

passion_for_javaa at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

>I just wanted to know is it possible to write method declaration/prototype in the scriptlet tag of a JSP?

Have you tried it?

Ask yourself this question

- Can you declare a java method within another java method?

You can write between scriptlet tags <% %> anything that would go into a standard java method. As I mentioned before anything in those tags actually ends up as part of the _jspService() method of the JSP.

To aid your understanding, the best way to learn is by doing :-)

So try this stuff out.

Build a simple JSP. Compile it, and take a look in the [TOMCAT]/work directory to see the java servlet code generated from that JSP.

Its often easier (and quicker) to do things like that than to ask open ended questions on the forum :-)

So no, you can't declare methods within a java scriptlet because you can't declare a method inside another java method.

You could define an inner class within the jsp scriptlet tags if you wanted to.

I would not recommend it as good programming practice though.

Also notice that my answer to the "stupid requirement" above posed a number of questions. If I was asked that question in interview, I would respond in much the same way. Maybe not using the term "stupid requirement" but asking the same questions, and exploring the same alternatives. I would take the question as an opportunity to show my understanding of the underlying issues, and the standard approaches for dealing with them.

evnafetsa at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

>Have you tried it?

Yes. And it did not work out.

May be the following points may help others too,,

->Anything I write in scriptlet tags goes into the service method of the servlet.

->A variable declared in a scriptlet tag appears in the service method of the servlet

->A variable declared in a <%! %> tag appears inside the class (not inside any method but like a normal variable like we declare in a class under public section).

Evnafets: Thanks so much for your response.

passion_for_javaa at 2007-7-12 17:35:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...