Hi Nicholas,
I thank you for your response. Here is a servlet that I have been trying to run, as
you can see it is from the course material of an university and if you run it at their
site it works. I have made some modifications like, instead of handling the doPost()
by calling doGet() from the method, I have called it directly. Also I have tried out
the various suggestions that I found in the archives.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
/** Shows all the parameters sent to the servlet via either
* GET or POST. Specially marks parameters that have no values or
* multiple values.
* <P>
* Part of tutorial on servlets and JSP that appears at
* http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
* 1999 Marty Hall; may be freely used or adapted.
*/
public class ShowParameters extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String type= request.getContentType();
System.out.println(request.getContentLength());
System.out.println(type);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading All Request Parameters";
StringBuffer sb = new StringBuffer();
sb.append(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<TR BGCOLOR=\"#FFAD00\">\n" +
"<TH>Parameter Name<TH>Parameter Value(s)");
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
sb.append("<TR><TD>" + paramName + "\n<TD>");
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
sb.append("<I>No Value</I>");
else
sb.append(paramValue);
} else {
sb.append("<UL>");
for(int i=0; i<paramValues.length; i++) {
sb.append("<LI>" + paramValues[i]);
}
sb.append("</UL>");
}
}
try{
sb.append("</TABLE>\n</BODY></HTML>");
response.setContentLength(559);
System.out.println("Buffer length" + sb.length());
out.print(sb.toString());
out.close();
}catch(Throwable e){System.out.println("Inside socket exception");}
}
}
Regards
Mathew
>>> Nicholas Whitehead <[EMAIL PROTECTED]> 01/04/00 11:00AM >>>
Mathew;
It would be helpful if you could post some code, since
I am not sure that any data you have provided is
sufficent to diagnose the problem.
//Nicholas
--- Matthew George <[EMAIL PROTECTED]> wrote:
> Hello.
>
> My problem has been that I am unable to get the
> doPost method to work. The error that I get is
> "Connection reset by peer" . I am using the servlet
> runner utility with jsdk 2.1 and the operating
> system is WindowsNT. The browser that I am using is
> Netscape 4.6
>
> I tried the work arounds like writing the whole
> output to a StringBuffer and then writing the
> StringBuffer to the PrintWriter. I have used
> setContentLength() to the exact length of the output
> and also tried with exact length plus two as
> someone suggested.
>
> I would be grateful if someone would confirm whether
> this is a problem with servlet runner. I am using
> Jason Hunter's book to teach myself servlets and any
> suggestion about how to run the doPost() examples,
> using my existing configuration and without changing
> it to a doGet() will be greatly appreciated.
>
> Regards
> Mathew
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED]
> and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives:
>
http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
>
http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help:
> http://www.lsoft.com/manuals/user/user.html
>
=====
"And what causes me to run?
'Cause you're a...
Big Black Furry Creature From Mars"
--
Nicholas Whitehead
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://messenger.yahoo.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html