Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

error in this statement [import="com.oreilly.servlet.MultipartRequest"]

843841Feb 23 2005 — edited Feb 23 2005
hai,

iam designing jsp page where i use thi class i.e.,

import="com.oreilly.servlet.MultipartRequest"

for this iam using j2ee server i istalled jdk and j2ee.

when i run the following code iam getting error " unabe to compile class import="com.oreilly.servlet.MultipartRequest" "

what else should i do

please help me anyone


code is

<%@ page language="java" %>
<%@ page import="java.text.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.net.*" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="com.oreilly.servlet.ServletUtils" %>

<%!
String uri="";
Vector files=new Vector();
String pathf="";
%>

<%!
public static String FORM_ACTION = "method";
public static String ACTION_ATTACHFORM = "Attachments";
public static String ACTION_ATTACHFILE = "AttachtoMessage";
public static String ACTION_FILEREMOVE = "fileRemove";
public static String ACTION_SEND = "Send";
%>


<%
pathf=DNet.getDataFilesPath()+"/ActivityManagementNew";
pathf=pathf+"/";

uri=request.getRequestURI();
HttpSession ss=request.getSession(true);
String persno=(String)ss.getAttribute("persno");

String method = request.getParameter(FORM_ACTION);
//System.out.println("method"+method);

if (method ==null) {
}
else if((method!=null) && (method.equals(ACTION_ATTACHFORM)))
{
attachForm(request, out, files,0);
}
else if((method!=null) && (method.equals(ACTION_ATTACHFILE)))
{
attachFile(request, out);
}
else if((method!=null) && (method.equals(ACTION_FILEREMOVE)))
{
removeFile(request, out);
}
%>

<%! int inc=0; %>
<%!
public void attachForm(HttpServletRequest req,JspWriter out,Vector files,int size)
throws ServletException, java.io.IOException
{
out.println("<html>");
out.println("<head><LINK href=dmail.css rel=stylesheet>");
out.println("<title> Attach File </title>");

out.println("<Script Language=JavaScript>");
out.println("list=new Array();");
out.println("function putattach(pos,name) {");
out.println(" list[pos]=name; }");
out.println("function listattach() {");
out.println("if((window.opener.document.composeform.list)!=null)");
out.println("window.opener.document.composeform.list.value=list;");
out.println("window.close();}");
out.println("</script>");

out.println("</head>");
out.println("<body bgcolor='#EEEEEE' text='#494949' link='#9966CC' vlink='#009999' alink='#CC0066' ><center>");
out.println("<table>");
out.println("<TR align=middle bgColor=#eeeecc><TD colSpan=7 align=center><FONT class=f>&nbsp;<B>Attachments ");
out.println("</B> </FONT></TD></TR>");
out.println("</table>");

out.println("<form action="+uri+"?method="+ACTION_ATTACHFILE+"&size="+size+" ENCTYPE=multipart/form-data method=post>"+
"<center><table width=400 border=0><tr><td><ol>"+
"<li><p>Click the <b>Browse</b> button to select the file that"+
" you want to attach, or type the path to the file in the box below.<br>"+
"Attach File: <input name=attfile type=file> </p>"+
" </li><li><p>Click the <b>Attach to Message</b> button.<br>"+
" The transfer of an attached file may require 30 seconds to up to 10 minutes.<br>"+
"<center><input type=submit name=method value=\""+ACTION_ATTACHFILE+"\"></center></form></p>"+
"</li> <li><p>Repeat Steps 1 and 2 to attach additional files. Click"+
"the <b>Done</b> button to return to your message.</p></li></ol><br>"+
"<center><Input type=button value=Done onClick=listattach()></center>"+
"</td></tr></table>"+
"<form method=post action="+uri+">"+
"<input type=hidden name=size value="+size+">"+
"<hr width=400><table width=400 border=0>"+
"<tr><td><select name=attachlist size=5 multiple>");
if(files!=null)
{
for(int i=0;i<files.size();i++)
out.println( "<option value="+i+">"+(String)files.get(i)+"</option>");
out.println("</select>");
out.println("<Script language=JavaScript>");
for(int i=0;i<files.size();i++)
out.println("putattach("+i+", '"+(String)files.get(i)+"')");
out.println("</script>");
out.println("</td><td><input type=hidden name=method value="+ACTION_FILEREMOVE+"><input type=submit value=Remove> </td></tr>");
}else out.println("<option value=-1>-- Message Attachments -- </option></select>");
out.println("<tr><td><b>Current total ="+size+"K</b></td></tr>"+
"<tr><td colspan=2>Each file size cannot exceed 20MB. To remove an attachment,"+
"select the file from the list and click the <b>Remove</b> button. </td>"+
"</tr> </table></form></center>");
out.println("</body></html>");
out.flush();
// out.close();
}


public void attachFile(HttpServletRequest req,JspWriter out)
throws ServletException, java.io.IOException
{
HttpSession session=req.getSession();
Vector files=(Vector)session.getValue("files");

int Fsize=0;
try{
String user=(String)req.getSession().getValue("PERSONALNO");
File f=new File(pathf+"/Temp/"+user);
if(!f.exists())
f.mkdir();
MultipartRequest multi =new MultipartRequest(req, pathf+"/Temp/"+user, 20 * 1024 * 1024);
Enumeration efiles = multi.getFileNames();
String filename=null;
Fsize=Integer.parseInt(req.getParameter("size"));
while (efiles.hasMoreElements())
{
String name = (String)efiles.nextElement();
filename = multi.getFilesystemName(name);
}
File ft=new File(pathf+"/Temp/"+(String)req.getSession().getValue("PERSONALNO")+"/"+filename);
long size=ft.length();
if(filename!=null)
{
if(size<1024)
Fsize=Fsize+1;
else
Fsize=Fsize+java.lang.Math.round((float)size/1024);

if(files==null)
files=new Vector(); // to keep track of attached files
files.add(filename);
session.putValue("files",files);
}
attachForm(req,out,files,Fsize);

}
catch(Exception e)
{
e.printStackTrace();
}

}


public void removeFile(HttpServletRequest req,JspWriter out)
throws ServletException, java.io.IOException
{
HttpSession session=req.getSession();
Vector files=(Vector)session.getValue("files");

int j;
int FSize=Integer.parseInt(req.getParameter("size"));
String st[]=req.getParameterValues("attachlist");
String user=(String)req.getSession().getValue("PERSONALNO");
if(st!=null)
{
for(int i=0;i<st.length;i++)
{
j=Integer.parseInt(st);
File f=new File(pathf+"/Temp/"+user+"/"+(String)files.get(j));
long s=f.length();
if(s<1024) s=1;
else s= java.lang.Math.round((float)s/1024);
FSize=(int)(FSize-s);

if(files==null)
files=new Vector(); // to keep track of attached files
files.remove(j);
session.putValue("files",files);
f.delete();
}
}
if(files.size()==0)
{
files=null;
File f=new File(pathf+"/Temp/"+user);
f.delete();
}
attachForm(req,out,files,FSize);

}

%>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2005
Added on Feb 23 2005
2 comments
409 views