Thanks for your quick responses.
I already tried to work with relative pathes, but sometimes the
hostmodus will not work properly and sometimes the webmodus will not
work.
Therefore I decided to write a servlet (it was mentioned in other
threads already).
My servlet looks like this:
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException
{
// Get the absolute path of the image
String outPutLocationFile =
(ServerHelper.getImageWorkingDirectory()).trim();
String filename = request.getParameter("img"); // get
the name of the requested image
String filePathName = (outPutLocationFile + File.separator +
filename).trim();
ServletContext sc = getServletContext();
String mimeType = sc.getMimeType(filePathName);
logger.info("outPutLocationFile: " + outPutLocationFile);
logger.info("filename : " + filename);
logger.info("filePathName : " + filePathName);
logger.info("mimeType : " + mimeType);
if (mimeType == null)
{
logger.error("Could not get MIME type of: " +
filePathName);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// Set content type
response.setContentType(mimeType);
// Set content size
File file = new File(filePathName);
response.setContentLength((int)file.length());
// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0)
{
out.write(buf, 0, count);
}
in.close();
out.close();
}
The servlet is called by the client using the Requestbuilder (request
parameters are directly encoded in the url string):
try
{
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST ,
imgUrl);
rb.sendRequest(null, new RequestCallback()
{
public void onError(Request request, Throwable
exception)
{
Window.alert("Error ("+ exception +")");
}
public void onResponseReceived(Request request, Response response)
{
response.getStatusText();
}});
}
I receive the repsonse with status ok. But now I don't know how to
display the image ? Somebody wrote something about using the img tag
with the src attribute.
Any help would be appreciated to solve this issue.
I think this is really a better way to display the images dynamically.