This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to upload images on server  RSS feed

Kabir Rahi
Posts: 2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I'm new in java world.
I'm working on JSF framework
so please help me,

I working on admin module on E-Greeting card project, like 123greetings.

Images store in project folder not in database. In database only link path store.

I'm Not able to store images on project folder. Images store temporary on server.
so please help me,

here i attach the code

[1] This JSF code.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri=""%>
<%@taglib prefix="h" uri=""%>

<%@taglib prefix="rich" uri="" %>
<%@taglib prefix="a4j" uri=""%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Birthday Card</title>
<h1><h:outputText value="Upload Image"/></h1>

<h:panelGrid columns="2" columnClasses="top,top">
<rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
acceptedTypes="jpg, gif, png, bmp" allowFlash="#{fileUploadBean.useFlash}">
<a4j:support event="onuploadcomplete" reRender="info" />
<h:panelGroup id="info">
<rich:panel bodyClass="info">
<f:facet name="header">
<h:outputText value="Uploaded Files Info" />
<h:outputText value="No files currently uploaded"
rendered="#{fileUploadBean.size==0}" />
<rich:dataGrid columns="1" value="#{fileUploadBean.files}"
var="file" rowKeyVar="row">
<rich:panel bodyClass="rich-laguna-panel-no-header">
<h:panelGrid columns="2">
<a4j:mediaOutput element="img" mimeType="#{file.mime}"
createContent="#{fileUploadBean.paint}" value="#{row}"
style="width:100px; height:100px;" cacheable="false">
<f:param value="#{fileUploadBean.timeStamp}" name="time"/>
<h:panelGrid columns="2">
<h:outputText value="File Name:" />
<h:outputText value="#{}" />
<h:outputText value="File Length(bytes):" />
<h:outputText value="#{file.length}" />
<rich:spacer height="3"/>

<a4j:commandButton action="#{fileUploadBean.clearUploadData}"
reRender="info, upload" value="Clear Uploaded Data"
rendered="#{fileUploadBean.size>0}" />


[2] This is bean file of Jsf

import java.util.ArrayList;

import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;

* @author Ilya Shaikovsky
public class FileUploadBean{

private ArrayList<FileTest> files = new ArrayList<FileTest>();
private int uploadsAvailable = 1000;
private boolean autoUpload = true;
private boolean useFlash = true;
private boolean createTempFiles = true;

public int getSize() {
if (getFiles().size()>0){
return getFiles().size();
return 0;

public FileUploadBean() {

public void paint(OutputStream stream, Object object) throws IOException {
public void listener(UploadEvent event) throws Exception{
UploadItem item = event.getUploadItem();
FileTest file = new FileTest();



public String clearUploadData() {
return null;

public long getTimeStamp(){
return System.currentTimeMillis();

public ArrayList<FileTest> getFiles() {
return files;

public void setFiles(ArrayList<FileTest> files) {
this.files = files;

public int getUploadsAvailable() {
return uploadsAvailable;

public void setUploadsAvailable(int uploadsAvailable) {
this.uploadsAvailable = uploadsAvailable;

public boolean isAutoUpload() {
return autoUpload;

public void setAutoUpload(boolean autoUpload) {
this.autoUpload = autoUpload;

public boolean isUseFlash() {
return useFlash;

public void setUseFlash(boolean useFlash) {
this.useFlash = useFlash;

public boolean iscreateTempFiles(){
return createTempFiles;

public void setcreateTempFiles(boolean createTempFiles){
this.createTempFiles = createTempFiles;


public class FileTest {

private String Name;
private String mime;

private long length;
private byte[] data;

public String getName() {
return Name;
public void setName(String name) {
Name = name;
int extDot = name.lastIndexOf('.');
if(extDot > 0){
String extension = name.substring(extDot +1);
} else if("jpg".equals(extension)){
} else if("gif".equals(extension)){
} else if("png".equals(extension)){
} else {
mime = "image/unknown";
public long getLength() {
return length;
public void setLength(long length) {
this.length = length;

public String getMime(){
return mime;

public byte[] getData() {
return data;
public void setData(byte[] data) { = data;

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!