Vaibhav Shridish

Greenhorn
+ Follow
since Jun 06, 2002
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
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vaibhav Shridish

This servlet is being accessed from a html page which has a submit button.
In reply this servlet has to display the count of
the number of times the servlet has been accessed.
==============================================
can some one please let me know y the following code is not displaying the count ??
===============================================
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class CounterServlet extends HttpServlet
{
Integer count;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
HttpSession hs =req.getSession(true);
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>CounterServlet</TITLE>");
out.println("<BODY>");
out.println(hs.isNew());
if(hs.isNew())
{
hs.setAttribute("counter",new Integer(0));
}
count=(Integer) hs.getAttribute("counter");

synchronized(count)
{
count=new Integer(count.intValue()+1);
out.println("Count value is -"+count.intValue());
}
out.println("<center>");
out.println("<B>The counter Servlet has been accessed "+ count.intValue() +" times");
out.println("</center>");
out.println("</BODY>");
out.println("</HEAD>");
out.println("</HTML>");
out.close();
}
}
19 years ago
Hi
can someone help me solve this problem ?
Problem 1] is there some way i can replace the
out.println statements by directing the control to
another html page.
How do i achieve this ??
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
PrintWriter out=new PrintWriter(resp.getOutputStream());
String email = req.getParameter("email");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>subscribeServlet</TITLE>");
out.println("<BODY><CENTER>");
out.println(email);
if((testemail(email))==true)
{
out.println("<br>");
out.println("Subscription Success");
out.println(req.getRequestURI());
}
else
{
out.println("<br>");
out.println("Failure");
out.println(req.getRequestURI());
}
/*
out.println("Error occured please reenter ur email id");
out.println("<form method="POST" action="http:/\"+"/127.0.0.1:8080/examples/servlet/subscribeServlet4"+"><center>Enter Your Email Address : <input name = "email" value = " " type = "text" size= "40"><br><br><input type="submit" value="Subscribe"><br></center></form>");
*/
out.println("</CENTER></BODY>");
out.println("</HEAD>");
out.println("</HTML>");
out.close();
}[/CODE]

Edited by MC to use UBB Code tags
(oh never mind, it blows up the page)
[ February 21, 2003: Message edited by: Mike Curwen ]
19 years ago
I have downloaded jsdk and tomcat
I tried to run the following program HelloWorld.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
It is showing me an error saying
Package javax.servlet not found.
my javax directory doesnt have servlet directory ...?
Do i need to download javax from somewhere ?
plz let me know ...
19 years ago
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new BorderLayout());
add(bSouth,"South"); //1
add(bWest,"West"); //2
add(bEast,"East"); //3
add(bCenter,"Center");//4
add(bNorth,"North"); //5
//Here
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}

public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
I modified the question and my question is
I move setVisible(true) to //Here
Y do i see only "North" there .... irrespective of the order of stmts 1,2,3,4,5?
Yeah thanz a lot all ....
got it finally ...
Yeah thanz a lot paul ...
Actually i DISCOVERED that yesterday night ....
and that was the weird behaviour i was talking
abt and never understood properly untill i
experimented again and again.

How do i access the myclass in the interface ?
[ Jess added UBB [CODE] tags to preserve whitespace ]
[ June 19, 2002: Message edited by: Jessica Sant ]
Good work paul .. i got only 70% in the 1st 100
and guess whatttttt the remaining 100 drove me
crazy and made me forget the basics for a moment
i had spent 2 days analysing the mistakes i have
committed in the remaining 100 and am not yet done
and particularly those questions on strings I
tell you .... 2&^*(^(*&^$&*&6 DROVE ME LITRALLY
mad ... i did an exhausting testing on the way
string class works and found out its really
really wierd. ..
i shall post those questions on strings later
today ....
when are you taking your certification exam ?
Congrats .....
I am to take the scjp exam with in a few days
could u plz let me know the average score u used
to get in the mock exams ??
also please let me know which mock exam is at the
same difficulty level as that of the main exam ?
Your input is very very very valuable for my
preparation ...
thanks
19 years ago
Hi geeta
i am taking sun exam with in 2 weeks in hyd..
Hey how much are you scoring in the Mock exams ?
but wht difference does it make wht its suns old
release or the new one ?
thanz all for replies ....
corey .. i have gone thru the declarations section
i was under the impression that const cannot
THROW exceptions ...
Then what did the statement from rasmussen mean ?
"constructors cannot specify exceptions in
header" ??
Hey paul
i got that question from this link
http://sanjayahuja.tripod.com/tech/scjp/scjp.html
i could get only 5/20 in the questions from 181
to 200 .....
valentin... Thanks for that link ...
can you let me know how much do you think one
should be scoring in the 200 questions in the
link above?
Well plz refer to page number 101 in which he says constructors cannot specify exceptions in header .....
Why is this working then ?
class base
{
base() throws Exception
{
try
{
System.out.println("I am in the Base : Try");
throw new Exception();
}
catch(Exception e)
{
System.out.println("I am in the Base : Catch");
}
throw new Exception();

}
}
public class derived extends base
{
derived() throws Exception
{

}

public static void main(String args[])
{
try
{
new derived();
}
catch(Exception e)
{
}
}
}
3)Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.
a)True
b)False
Why is the ans False ??
Question)Class fields with the following modifiers will not be serialized
a)private,
b)static,
c)transient,
d)protected
Ans = c,d.
Can someone explain ?