Nishant Vartak

Greenhorn
+ Follow
since Nov 29, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Nishant Vartak

www-03.ibm.com/certify/tests/objL829.shtml

Follow the above link for details.
Hi,
Is it necessary for attributes in ServletRequest\ServletResponse to be always serializable?I need to populate OutputStream in request\response.

Regards,
Nishant V
10 years ago
WE don't have a file, but Stream of data. This can be of any content-type - HTML,CSV,XML,PDF. We want to display it only if its a HTML , for rest we will have to give a Save As option to user. This can be achioeved by setting "content-disposition" as "inline" and "attachment" resp. This logic will be present in my (Streaming) Servlet. The OuputStream which needs to be passed to this (Streming)Servlet is generated in Other Servlet (Master Servlet). The responsiblity of Master Servlet is to display Master JSP. Master JSP includes a set of JSP and to display Stream it will invoke Streaming Servlet through iFrame.
Can someone suggest how this can be achieved. i.e inter-Servlet communication through JSP. withouty passing the "OutputStream" object into session.
10 years ago
When i issue a request to Servlet(Master) it returns me a OutputStream. I cannot directly display this OutputStream by passing it to ServletStream as in that case the Servlet will display only the contents of this stream.
I need to display a master JSP and in one of its frame show the contents of this stream.
So the only solution which we could think of is store the OutputStream object in session in servlet(Master) and return with Master JSP.
Then in Master JSP have a iFrame which will invoke a Servlet (Streaming Servlet). The output from this Servlet will be a Stream which was set in session by Master Servlet.

iFrame will call 'init' method of Servlet. To overcome this problem we make iframe call a JSP which will auto submit to this Servlet (Streaming Servlet). This is achieved by calling a javascript function on "onLoad" event of HTML.

Let me know if there is a easier solution for this problem.
10 years ago
Missed out on certain aspects. The Stream is stored in session. So i need to get access to HttpRequest object to get the stream from session. Can you suggest a way by which i can invoke either a get or a post method through iFrame?

Also, does Websphere Application Server support "iFrame" in a JSP.
iFrame works with tomcat on my browser (IE 6.0). So browser not supporting iFrame is rule out.

Thanks and Regards
Nishant V
10 years ago
Hi,
I need to display a JSP which will include some JSP (like menu jsp, header jsp) etc. These JSPs will be paint the left hand side and bottom side of page. In the remaining section, i should be able to display the OutputStream.

If this OutputStream is a HTML File, it should be displayed on the screen. If is a PDF/CSV/XLS, it should be available as download.
Can someone suggest how this can be achieved?

My Solution though not effective: As I can figure it out I will have to make two servlet call. First a call to Master Servlet to display the Master JSP (which will display all included JSP) and then other call to a different Servlet (Stream Servlet) to recieve a stream file.
I tried to invoke the Stream Servlet through "IFRAME" , but failed as it just invokes Servlet's init() method.


Some More info Can someone tell me which amongst the below mention files can be displayed with out installation of any third party software in browser as inline?
PDF,HTML,CSV,XML,RTF,XLS etc.
Our SearchWe have found that to display PDF inline, we need a Adobe Activex Plugin installed for respective browser. So PDF will be a presented as dowbnload.

Thanks and Regards,
Nishant Vartak
10 years ago
Should i write the code to connect DB in ContextListener and then populate the result in ContextAttribute. Based on the result i can dedcide to throw javax.servlet.UnavailableException in servlet init() method.
or should i write the code in servlet's init() method.
Does it make any difference?
10 years ago
I want to stop servlet from getting loaded based on following conditions.
1)A parameter is not matched.(It might be in DD or application specific properties file).
2)based on a parameter fethced from database.

What should i use amongst the following:
1. servlet's init().
2. ServletContext Listener.
Which is better/appropriate?
for database connection i would like to do a look up on aready configured resource in Application server.
10 years ago
A)Which class implements ServletContext interface. Why is the concrete class not present in API?(src:Tomcat servlet API)

B)The only handle to ServletContext is via ServletConfig.i.e. getServletConfig().getServletContext()
getServletConfig():API doc says that this method invokes abive method to fetch ServletContext.
Why is ServletContext coupled with ServletConfig?

C)thread-safety of context attributes(src:HFSJ pg no:197)
It mentions that ServletContext should be syncrhonized in every Servlet.
Does it mean that there is seperate instance of ServletContext for every Servlet?
But its said that there is a single ServletContext for every web-app(lets not talk abt distributed).What does the preivous statement signify.
Hi,
I wish to take SCWCD 1.4 (CX-310-081).Need to know if Sun has plans to revised this exam.

Thanks and Regards,
Nishant V
[ July 02, 2007: Message edited by: Nishant Vartak ]
Thanks to Java Ranch for their guidance.
~Nishant V
10 years ago
public class TeSet {
2. public static void main(String args[]) {
3. int m = 2;
4. int p = 1;
5. int t = 0;
6. for(;p < 5;p++) {
System.out.println("p ="+p+", t ="+t);
7. if(t++ > m) {
8. m = p + t;
9. }
10. }
11. System.out.println("t equals " + t);
12. }
13. }
explaination.
In above example insert the line between 6 & 7. Its quite cleared that loop executes four times. adn t is incremented four times. Hence 't' should be four.
As far as for loop is concerned it should always have boolean condition.
other things are optional i.e declaration and iterator condition.

2.
class Value{ public int i = 15;} //Value
public class Test{
public static void main(String argv[]) {
Test t = new Test();
1.t.first(); }
public void first() {
2.int i = 5;
3.Value v = new Value();
4.v.i = 25;
second(v, i);
5.System.out.println(v.i); }
public void second(Value v, int i) {
6.i = 0;
7.v.i = 20;
8.Value val = new Value();
9.v = val;
10.System.out.println(v.i + " " + i);
}} // Test

line1: a stack is created for method 'first()'.
line 2: local variable i in stack is assigned value 5. its scope is till line5. It will not be visble when method "second" is being executed.
line3 bejct of type Value with reference 'v' is added to heap. its instnace variable i has value '15'. i.e v.i = 15;
line 4: instance variable i of Value(refered by V) is overwrriten i.e v.i = 25;
line 6: local variable i is created with value '0'. its scope exists till line 10.
line 7: inside method 'second()'. another object reference of type v points to our Value Object in heap. i.e. v.i = 25;so now two Object references points to same Value Object in heap. its modified to '20' so now v.i = 20;
line 8: New Value object is created and is referenced by 'val' i.e val.i==15.
so now our heap contains two 'Values' objects(v.i = 25 val.i = 15) and three references (v from first(), v from second(its parameter of second method) and val )
line 9: v= val; ('v' from second method will now refer to 'val' i.e v.i = 15)
line 10: local variable i of method second and v of method second.
line 5. on line 7 the state of object was modified. so now the Object reference v (of first method) is 20 . i.e v.i = 20
same code can be re written as:

class Value{ public int i = 15;} //Value
public class Test{
public static void main(String argv[]) {
Test t = new Test();
t.first(); }

public void first() {
int i1 = 5;
Value v1 = new Value();
v1.i = 25;
second(v1, i1);
System.out.println(v1.i); }

public void second(Value v2, int i2) {
i2 = 0;
v2.i = 20;
Value val = new Value();
v2 = val;
System.out.println(v2.i + " " + i2);
}} // Test
The answer is -1. Can someone please explain.
Can someone please explain the statements in quotes below with examples? They are generics tutorial avilable at source:http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
7.1 A Generic Class is Shared by all its Invocations
"As consequence, the static variables and methods of a class are also shared among
all the instances. That is why it is illegal to refer to the type parameters of a type
declaration in a static method or initializer, or in the declaration or initializer of a static
variable."
TIA.
For SCJP5.0,
One is suppose to know whether the exception is thrown by JVM or programtically. how can one logically deduce this?Is there any relation between exception thrown by JVM with RuntimeException?
[ May 13, 2007: Message edited by: Nishant Vartak ]