arvind

Greenhorn
+ Follow
since Aug 27, 2001
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 arvind

I have been able to run J2ee Server and run some of the applications in EJB say like Fibonacci series but got problems while executing multiple beans at a time.Also got problems while configuring the Web Logic server.Kindly Suggest.
16 years ago
hi,
i am using the upload component of oreilly and being successfully able to upload a component to a desired folder.The problem i am facing is that when i upload a particular image/file i want the name of image/file to be inserted in a database so that i can call it later as to when required.for e.g i want to upload test.htm in a particular folder like yogesh. The path of the file will be(..\test.htm). the test.htm is successfully uploaded to a folder but i want the test.htm to be inserted a database say xyz which has a table called test with fields like name,image and so on. I would like to have my test.htm to be inserted in the table test in it's field image.
17 years ago
I have been successfully able to execute the upload component of oreilly and been able to upload components in a desired folder.I want to get the information of the material that has been uploaded so that i am able to save it in the database for future references,Please help
arvind
17 years ago
i am trying to use a banner rotator in servlets.can anybody help me by providing a source code.
17 years ago
hi! malhar,
give the real path by using the foll. servlet:i.e(req,www/htdocs/server-name/malhar,1024*1024)
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class test2 extends HttpServlet
{

public void doGet(
HttpServletRequestrequest,
HttpServletResponseresponse
) throws ServletException, IOException
{
PrintWriterout;
Stringtitle = "Output";
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
out = response.getWriter();

out.println("checking for include files");
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("path information "+ request.getPathInfo());
out.println("<br>");
out.println("servlet information "+ request.getServletPath());
out.println("<br>");
out.println("realpath information "+ request.getRealPath("/"));
out.println("<br>");
out.println("protocol information "+ request.getProtocol());
out.println("</BODY></HTML>");
out.close();
}
}
17 years ago
hi! alok,

you can try out this code:it works perfectly well
Ist part:
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class T1 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,"give the real path e.g www/htdocs/document name",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>");
}
}
IInd part :
<html>
<head>
<title>File Upload</title>
</head>
<body bgcolor=bisque>
<form ACTION="http://server-ip address/servlet/T1" METHOD=post ENCTYPE="multipart/form-data" >
which file do you want to upload ? <input type=file name=file><br>
which file do you want to upload ? <input type=file name=file1><br>
which file do you want to upload ? <input type=file name=file2><br>
which file do you want to upload ? <input type=file name=file3><br>
which file do you want to upload ? <input type=file name=file4><br>
which file do you want to upload ? <input type=file name=file5><br>
<input type=submit value=submit>
</form>
</body>
</html>
17 years ago
dear friends,
i would like someone to guide me as how to use server side includes in servlets using apache web server(1.3.12 ver) and jserv.i have got a servlets folder on the server were i kept all my .class files and in the htdocs file i kept my html and shtml files .
the contents of my shtml file is as follows:
<html>
<head><title>SHTML test</title></head>
<body>
<h1>#1</h1>
Your IP address is <!--#echo var="REMOTE_ADDR"-->.
<h1>#2</h1>
This document's filename is <!--#echo var="DOCUMENT_NAME"-->.
<h1>#3</h1>
The Universal Time Coordinate is <!--#exec cmd="/bin/date --utc"-->.
Running another program makes for an example, but note
that the current time is available like so:
<!--#echo var="DATE_LOCAL"-->.
<h1>#4</h1>
Here I include a footnote.
<hr>
<!--#include file="footer.html"-->
<servlet code="http://server-ip address/servlets/SimpleServlet">
</servlet>
</body>
</html>
the contents of servlet is as follows:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends HttpServlet
{

public void doGet (
HttpServletRequestrequest,
HttpServletResponseresponse
) throws ServletException, IOException
{
PrintWriterout;
Stringtitle = "Simple Servlet Output";
//String p1=request.getParameter("param");
out = response.getWriter();

out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("<P>This is output from SimpleServlet.");
//out.println("check "+p1);
out.println("</BODY></HTML>");
out.close();
}
}
kindly let me know at the earliest.
17 years ago
hi! Sridhar,
first of all try running the code using servletrunner. you can save upload.html and upload.java,upload.class files in jsdk\examples folder.then using the browser properties open the html page eg C:\JSDK2.0\examples\upload.html.create a folder anywhere on your c:\drive say image. in your upload.java file in the MultiPartRequest give path like req,../image,1024*1024...
After selection of any file using the browse button ,clicking on the submit button ,the file will be send to the image folder which you had created.
this code works out well.
all the best.
17 years ago
hi! chaitanya,
you can try out this code:it works perfectly well
Ist part:
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class T1 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,"give the real path e.g www/htdocs/document name",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>");
}
}
IInd part :
<html>
<head>
<title>File Upload</title>
</head>
<body bgcolor=bisque>
<form ACTION="http://server-ip address/servlet/T1" 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>
17 years ago
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>");
}
}

17 years ago
i am not able to upload files on my server(apache &jserv).I get the following error namely:
java.lang.IllegalArgumentException: Not a directory: ../yogesh
at com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:109)
at test.doPost(test.java:11)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:521)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at org.apache.jserv.JServConnection.processRequest(JServConnection.java:317)
at org.apache.jserv.JServConnection.run(JServConnection.java:188)
at java.lang.Thread.run(Thread.java)
i used the following multipartrequest:
MultipartRequest multi = new MultipartRequest
(req,"../yogesh",5*1024*1024);
kindly suggest a solution(changes to be made) so that the files get uploaded in the folder yogesh.
17 years ago