sai sridhar

Greenhorn
+ Follow
since Aug 23, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by sai sridhar

Hi Manohar
How do i do so ??
I mean how do i register my servlet in the webserver ??
Thanks
sai

Originally posted by Manohar Karamballi:
Hai Sai!
May be it has to do with something in registering ur servlet in ur server
Rgds
Manohar


23 years ago
Hi all
Can any one give me suggestions as how to connect to a remote machine from a webserver ??
Thanks&Regds
sai
23 years ago
Hi all
I'm calling a servlet from a normal class without using a browser for HTTP requests..I get the following error when i try to capture the values returned by the servlet..
Can anyone please resolve this..

java.io.FileNotFoundException: http://localhost:8080/servlet/HelloServlet?&name=MyName&age=25
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at Hello.main(Hello.java:25)

The code which i wrote is :
import java.util.HashMap;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// getting the parameters
String name = request.getParameter("name");
String age = request.getParameter("age");
//putting them in a hashmap
HashMap hm = new HashMap();
hm.put("name", name);
hm.put("age", age);
//returning them
try {
ObjectOutputStream p = new
ObjectOutputStream(response.getOutputStream());
p.writeObject(hm);
p.flush();
p.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
This is the class that calls the servlet:
import java.net.*;
import java.util.*;
import java.io.*;
public class Hello {
public static void main(String args[]) {
ObjectInputStream is;
URL url;
String uri =
"http://localhost:8080/servlet/HelloServlet";
HashMap hash = new HashMap();
try {
//calling the servlet by passing params
url = new URL(uri + "?&name=MyName&age=25");
// open input stream and read the hashmap
// returned by the servlet
is = new ObjectInputStream(url.openStream());
hash = (HashMap) is.readObject();
// print it out
System.out.println(hash);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
Thanks in Advance
sai
23 years ago
Hi all
I upload a file to a webserver using a servlet.
How do i get the name of the file which is uploaded ???I'm using com.orielly.servlet package..
Is there any way to find out the name of the file which is uploaded prior to this line below in the code given down??
MultipartRequest multi =
new MultipartRequest req,"/temp",1024*1024);
If so,pl respond
Your help will be greatly appreciated
Thanks in advance
sridhar
Pl see : down given is my code for uploading a file
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class Upload extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{

res.setContentType("text/html");
PrintWriter out = res.getWriter();
try{
System.out.println(req.getHeader());
MultipartRequest multi =
new MultipartRequest req,"/temp",1024*1024);
out.println("<html>");
out.println("<head><title>UploadTest</head></title>");
out.println("<body>");
out.println("<h1>upLoadTest</h1>");
out.println("<pre>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements())
{
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println( name + " = " + value);
}
out.println("</pre>");
out.println("<h3> files : </h3>");
out.println("<pre>");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements())
{
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name : " + name);
out.println("file name : "+ filename);
out.println("type : "+type);
if (f!=null){
out.println("length : " +f.length());
out.println();
}
out.println("</pre>");
}
}
catch(Exception e)
{
out.println("<pre>");
System.out.println(e);
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body> </html>");
}
}
23 years ago
Hi,
We are using Apache Web Server under Unix.
We have a problem related to reloading of jsp files.
When jsp file is first time put into webserver
and accessed through the browser .java and .class files are created.
When we change the jsp file and access it again the file is not getting
reloaded with the changes. But we get the same old jsp file.
We tried after clearing the history files at browser level.
We tried after deleting the .java and .class files still we are not
able to get the new jsp file. Even when we delete the .java and .class
files, still we get the old jsp file.
We tried to set the property "autoreload= true" in "zone.properties" file
which is used during server startup, but not able to reload the new jsp
file.
We are able to get the new(changed) jsp files only if we restart the
web server. But we dont want to shutdown and restart the web server
everytime we make changes to jsp file. Can somebody help us with this???
23 years ago
Hi Aravind,
Thanks for u'r info.But sorry to tell you,i still get "404 PageNotFound " error..Seriously,i'm so bugged becoz i'm unable to figure out where i've mistaken
pl revert back if u find
Thanks a tonne
sridhar

Originally posted by arvind:
hi! sridhar,
u can try out this code ,it works:
Ist part:
<html>
<head>
<title>File Upload</title>
</head>
<body bgcolor=bisque>
<form ACTION="http://localhost:8080/servlet/upload" METHOD=post ENCTYPE="multipart/form-data" >
which file do you want to upload ? <input type=file name=file><br>
<input type=submit value=submit>
</form>
</body>
</html>
IInd part:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class upload extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException {
res.setContentType("text/html"); PrintWriter out = res.getWriter(); try{
MultipartRequest multi = new MultipartRequest
(req,"../image/trim",5*1024*1024);
out.println("<html>");
out.println("<head><title>UploadTest</head></title>");
out.println("<body>");
out.println("<h1>upLoadTest</h1>");
out.println("<pre>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()){
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println( name + " = " + value);
}
out.println("</pre>");
out.println("<h3> files : </h3>");
out.println("<pre>");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements()){
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name : " + name);
out.println("file name : "+ filename);
out.println("type : "+type);
if (f!=null){
out.println("length : " +f.length());
out.println();
}
out.println("</pre>");
}
}
catch(Exception e){
out.println("<pre>");
System.out.println(e);
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body> </html>");
}
}


23 years ago
Hi everyone,
I wanna upload a file to Javawebserver.I've downloaded
"com.oreille.servlet.*" package from www.servlets.com and has set the classpath.Everything is compiling fine and i wrote the following code in Html page
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form ACTION="http://localhost:8080/servlet/Test.class" METHOD=post ENCTYPE="multipart/form-data" >
what is your name ? <input type = text name=submitter> <br>
which file do you want to upload ? <input type=file name=file><br>
<input type=submit value=submit>
</form>
</body>
</html>
But,when i click on the submit button i get an error as "Http404" not found.
I wrote the following code as my servlet

public class Test extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
res.setContentType("text/html");PrintWriter out = res.getWriter();try{
MultipartRequest multi = new MultipartRequest
(req,"./public_html/temp",5*1024*1024);
out.println("<html>");
out.println("<head><title>UploadTest</head></title>");
out.println("<body>");
out.println("<h1>upLoadTest</h1>");
out.println("<pre>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()){
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println( name + " = " + value);
}
out.println("</pre>");
out.println("<h3> files : </h3>");
out.println("<pre>");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements()){
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name : " + name);
out.println("file name : "+ filename);
out.println("type : "+type);
if (f!=null){
out.println("length : " +f.length());
out.println();
}
out.println("</pre>");
}
}
catch(Exception e){
out.println("<pre>");
System.out.println(e);
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body> </html>");
}
}
pl revert back as this is urgent
Thanks
sridhar
23 years ago