How to upload an image in jsp page
hi,
I want to upload an image file with my jsp page, but i cannot do it,
I have used Jakarta common file upload for this & i have also read following file. But my code isnot working properly? Can you give me any example how to upload an image & how to display it?
Can u give me any source code? Please help me.
http://jakarta.apache.org/commons/fileupload/using.htmlwith regards
Bina
Hi,
But after writing the following code i have got following error? What's the problem of this code? please help me?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import ="java.util.*" %>
<%@ page import ="java.io.*" %>
</head>
<body>
<%
boolean isMultipart = FileUpload.isMultipartContent(request);
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
String name = item.getFieldName();
String value = item.getString();
//ring name= request.getParameter("")
%>
<%= name %>:<%= value %>
<%
} else {
%>
<%
InputStream stream = item.getInputStream();
OutputStream bos =
new FileOutputStream(getServletContext().getRealPath("/images"+"/"+ item.getName()));
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
bos.close();
stream.close();
item.delete();
%>
</body>
</html>Error is:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
FileUpload cannot be resolved
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
DiskFileUpload cannot be resolved to a type
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
DiskFileUpload cannot be resolved to a type
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
FileItem cannot be resolved to a type
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
FileItem cannot be resolved to a type
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
FileUpload cannot be resolved
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
DiskFileUpload cannot be resolved to a type
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
DiskFileUpload cannot be resolved to a type
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
FileItem cannot be resolved to a type
An error occurred at line: 13 in the jsp file: /uploadfileC.jsp
Generated servlet error:
FileItem cannot be resolved to a type
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Please help me.
With regards
Bina
Similar Messages
-
How to display uploaded image in jsp page.
Hello,
I am using struts 1.2.9 and and have uploaded image on the server. Now what I want to do display the image in jsp page after clicking on one link in jsp. I have tried many thing to display image in jsp page. But I am getting an error during displaying image in jsp. I have displayed absolute path in servlet. and used InputStream and outputstream to display image in jsp page.
Can any one help.
Thanks in advance
Manveer SinghFollow this. This topic is very popular recently on the forum.
-
How to get the full image directory when i upload the image to web page???
hai, how to get the full image directory when i upload the image to web page???
here is the example:
<form action="uploadfile.jsp" method="post">
image<input type="file" name="image" />
<input type="submit" value="submit"/>
<%
String s=request.getParameter("image");
%>
<%=s%>
</form>
i upload the image from C:\image\center.gif. i use request.getParameter just can get the image name like "center.gif". Can anybody help me how to get the full path name. Thanks a lot..There is no need to get the path. It is also fairly pointless as the server cannot access the client's local file system.
Carefully read this article how you can upload files the right way: http://balusc.blogspot.com/2007/11/multipartfilter.html -
How to upload the image and diplay the image in the browser using jsp
How to upload the image and diplay the image in the browser using jsp
thanks
shani'll suggest looking for sample code or tutorial with a relevant query in google, which as far more time than us to answer this type of reccurent question
-
How to Upload Mutilple Images in content repository?
Hi
How to Upload Mutilple Images in content repository?
I have a html which shd be displayed and it has 3 images which shd be displayed
in the same page
Here i am able to display the HTML uploaded in content repository
but the images are not displayed,since the path is not valid for the images.
Can any one hint me in this,
wating for the reply
Thanks in Adv
Regards
SureshSuresh, your html specifies an image at resources/images/privacy.gif - is that
image in your repository at the correct relative position to where yout html is?
Your html and repository structure must match. So if the html you posted is at
/BEA Repository/foo.html
then privacy.gif must be at /BEA Repository/resources/images/privacy.gif
James
"Suresh" <[email protected]> wrote:
>
>
>
Hi James
Here i have attached my sample html and image
My Repository Structure is as follows :
Virtual Content Repository
BEA Repository
MainImage type image
Privacy type i created
----StartDate
----EndDate
----File Upload
My HTML
<HTML>
<HEAD>
<TITLE> New Document </title>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</head>
<BODY>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="norBold"><img src="resources/images/privacy.gif"
width="123"
height="73">Privacy
Policy</td>
</tr>
<tr>
<td class="formHeadBack" height="19"><b> Privacy Policy</b></td>
</tr>
</body>
</html>
and
one image
Thanks in Adv
Suresh
"James Owen" <reply.to@newsgroup> wrote:
Suresh, how is your content structured and what does your html looklike?
If you
could post examples, that would be helpful.
thanks,
James
"suresh" <[email protected]> wrote:
Hi
How to Upload Mutilple Images in content repository?
I have a html which shd be displayed and it has 3 images which shd
be
displayed
in the same page
Here i am able to display the HTML uploaded in content repository
but the images are not displayed,since the path is not valid for the
images.
Can any one hint me in this,
wating for the reply
Thanks in Adv
Regards
Suresh -
Problem in displaying image on jsp page
I want to display an image on jsp page.I copied the image the image in WebContent folder.
I am able to see the image on the design pane when using the following code:-
<img src="/image.gif" height="50" width="50"> but when i run it in the browser nothing gets diplsyed.
also when i use the image container and select the source option that image is not displayed in the WebContents file..plz help.Hi,
Seems that the Problem is there with the way how you specifuied the Image relative Path:
You have specified the below: The opath of image starts with (/) forward slash:
*<img src="/image.gif" height="50" width="50">*
It means to access this Image WebLogic Container will form a Path like this:
http://localhost:7001/image.gif
BUT may be the image is available inside your Context root: So Change the <Img> tag like following in your JSP:
*<img src="image.gif" height="50" width="50">*
(*NOTE:* Never Start your src path with a Preceesing /)
Now WLE will consider the path like below ..if your Applications Context root is "TestApp"
http://localhost:7001/TestApp/image.gif
I am Assuming that Inside the TestApp Application "image.gif" And "your.jsp" jSP pages are Co-Located (Means available in the Same Directory).
Thanks
Jay SenSharma
http://jaysensharma.wordpress.com (WebLogic Magical Stuff) -
How to upload a image file ....
Hi
Need some tips ....
How to upload a image file?
How to limit the size of the file?
if the image is big in size means how to make it small ?
Is it possible of compressing the file before storing ..?
thanks in advance
kumarYou may find the following articles useful for the JSP/Servlet part:
Uploading files: http://balusc.blogspot.com/2007/11/multipartfilter.html
Downloading files: http://balusc.blogspot.com/2007/07/fileservlet.html -
How to print new line in jsp page
hi
how to print new line in jsp page
thanks\n - new line character is in java specific not HTML
specific.Well, if the correct line separator sequence (by far not always \n) would be used, it does add a new line to the HTML output. Too bad that you don't want to see HTML but formatted text. The BR tag is a formatting element for the displayed text, not a line break in HTML. ;) -
How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
using RequestDispatcher..its not possible..becoz
RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
rd.foward(req,res);
Here the request and response are null objects..
So mi question can frame as how can i get request/response in servlet's init method()..Hi guys
did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:519)
at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
so plz do let me know how to call a jsp in the start up of a servlet.
Thanks
Vidya -
How to enable the EL in jsp page
hi can u tell 'how to enable the EL in jsp page'?
*I am getting below exception in tomcat when i inclued +<%@ page isScriptingEnabled="true" isELEnabled="true"%>+*
org.apache.jasper.JasperException: /index.jsp(1,1) Page directive has invalid attribute: isScriptingEnabled
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)
org.apache.jasper.compiler.JspUtil.checkAttributes(JspUtil.java:311)
org.apache.jasper.compiler.Validator$DirectiveVisitor.visit(Validator.java:106)
org.apache.jasper.compiler.Node$PageDirective.accept(Node.java:590)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2338)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2388)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2394)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2338)
org.apache.jasper.compiler.Validator.validate(Validator.java:1700)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:178)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) -
How to call BPEL process in JSP page
Hi
I am new to BPEL.please help me how to call BPEL process in JSP page.
Thank You...Check this thread ....
How can i call asyncronous BPEL process from Java Class????
Tom.. -
How to Hightlight the Data in Jsp Page
How to Hightlight the Data in Jsp Page,
I am doing doing search page,based on values given search page those are sent to servlet,in servlet based on some conditions if particuler id i am getting then i am redirecting to Respective jsp page with highlight the data from database..
Thanks in advance..."Highlighting data in JSP sounds strange".
Without looking at your search specific algorithms I feel you are finally going to display a page (HTML content) to user which contains highlighted text. Highlighting is not directly related to server side language you use (JSP, ASP, PHP etc.). This is purely HTML and CSS. However, server side script (such as JSP) should generate HTML content for getting highlight effect.
Following HTML shows highlighted text using background-color property on span element.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<p style="font-size:1.1em">This is a long paragraph which contains <span style="background-color: yellow;">highlighted text</span> and non highlighted text.</p>
</body>
</html>Thanks,
Mrityunjoy
Edited by: mrityunjoy on 14 Jun, 2010 3:30 AM -
HOW TO UPLOAD BACKGROUND IMAGES IN SMARTFORMS
HI
HOW TO UPLOAD BACKGROUND IMAGES IN SMARTFORMSHi,
goto se78 -> in the menubar click graphic and import to select ur images from ur system .. then click transport button .. it automatically gets into the smartform graphic image list.. then get into transaction smartform and use the image u imported into that..
U can import anykind of image which u have stored in ur pc through se78..
Regards,
Priya. -
How to upload a image or flash file as blob object in a table.
How to upload a image or flash file as blob object in a table.
What are all the possible ways we can do it.Searching the forum (or google) would be my first choice, as this question pops up every now and then.
Next without knowledge of your environment (jdev version and technology stack) it's hard to give a profound answer.
All I can say is that it's possible.
Timo -
Oepe-12.1.2.1-kepler how to use ADF Templates in JSP page
Hi all,
I use oepe 12.1.2.1 kepler 4.3 and creating JSP page but I can't see any ADF Rich Faces Page in JSP Templates Page of Preferences Dialog. How to use ADF Templates in JSP page?
Thanks,
ThomasSelect the JSP Templates link. Is the ADF Rich Faces Page template listed? Refer Creating the Login Page/4.
Introduction to the Oracle Enterprise Pack for Eclipse (OEPE) IDE
Maybe you are looking for
-
Adobe After Effects CS4 Third Party Content only installed on one of two computers
Hello, I installed Adobe Creative Suite CS4 MC on two systems. One system lists "Adobe After Effects CS4 Third Party Content" in Add/Remove Programs. This left me a bit baffled as to what this content is and why it only installed on one machine (i.e.
-
Problem when inserting "Thai language" string to MS Access with JSP
Dear sir, I have the problem when try to insert "Thai langusge" string to MS access database through JDBC in JSP page. The JSP page is shown in the following. <HTML><HEAD><TITLE>Personalt Information</TITLE> <%@ page contentType="text/html; charset=M
-
Hi, I am looking for some information about using Oracle ADF with E-Business Suite 11i, JDeveloper version is 9i. Most of the documentation I've seen has been specific for R12. Hoping someone can provide some information/links to documentation about
-
Where can I find a list of devices backing up to my icloud account
-
TS3276 My mac mail isn't working properly.
A box pops up saying the identity of pop.shaw.ca cannot be verified. The certificate for this server is invalid. You might be connecting to a server that is pretending to be pop.shaw.ca. How do I fix my macmail?