Tomcat IMAGEPATH IMAGEURL

Stephen Jones stephen.jones at VAISALA.COM
Wed Apr 11 04:13:17 EDT 2007


This may be of interest.

I have a java class responsible for creating a mapObj (in my case I populate the layers from info in an Oracle Table .. there are no physical map files). The class has a method that creates an imageObj and returns it as bytes. This is the code below  
public byte[] showMapAnswer(){
        aMap = (vaisalaMap) mapWindows.get(currentMapWindow);
        mapObj thisMap = aMap.getIcemap();
        imageObj mapImg = thisMap.draw(); 
        return mapImg.getBytes();     
    }
I have similar methods for returning reference maps, scalebar etc.

Then in my servlet I get the instance of my map and assign the byte from the above method to a byte array and write this to the response stream

   HttpSession session = request.getSession(true);
    System.out.print("*******************"+'\n');
    System.out.print("Draw : Session Called as "+session.getId()+'\n');
    System.out.print("*******************"+'\n');
    mapView thismapWindow ;

    thismapWindow =  (mapView) session.getAttribute("maps") ;
    int reqView;
    if (request.getParameter("view")==null){
        reqView=0;
    }
    else {
        reqView = Integer.parseInt(request.getParameter("view")); 
    }
    thismapWindow.setCurrentMapWindow(reqView);
    OutputStream o = response.getOutputStream();
    byte[] imgData = thismapWindow.showMapAnswer();  
    o.write(imgData);
    o.flush();

Then in your html or jsp you can simply add an image tag with the source being the above Servlet. 

Doing this avoids me having to save anything to disk.

Stephen

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]On
Behalf Of Umberto Nicoletti
Sent: 11 April 2007 08:18
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: Re: [UMN_MAPSERVER-USERS] Tomcat IMAGEPATH IMAGEURL


Tomcat by itself does not provide a handy way of creating aliases for
directories outside the application root. You should use apache as a
frontend to tomcat (with the jk connector) and then define an alias
(http://httpd.apache.org/docs/2.0/mod/mod_alias.html#alias) to map
'c:/mapserver_temp' to the 'temp' subdirectory of the url.

You should consider the use of apache as a tomcat frontend anyway
because of many other features like load balancing, faster serving of
static data (css, images, etc), better security, ssl, etc

HTH,
Umberto


On 4/11/07, LITTLE Nelson <nelson.little at tenix.com> wrote:
> Dave,
>
> Thanks for your reply.
>
> Firstly I updated my map file such that it now reads:
>
> IMAGEPATH "/mapserver_temp/"
> IMAGEURL "temp"
>
> I am able to write the image (image_file.png) via the mapserver object
> to the IMAGEPATH location with no troubles. However, how do I display
> that resultant image file in a web page? I thought the image would be
> available via http://loalhost:8080/myapp/temp/image_file.png
>
> Can anyone offer some help?
>
> Cheers,
> Nelson
>
> -----Original Message-----
> From: Dave Potts [mailto:dave.potts at pinan.co.uk]
> Sent: Wednesday, 11 April 2007 2:09 PM
> To: LITTLE Nelson
> Subject: Re: [UMN_MAPSERVER-USERS] Tomcat IMAGEPATH IMAGEURL
>
> LITTLE Nelson wrote:
> > Hello,
> >
> > I am trying to create a servlet application to run on the Tomcat 5.5
> web
> > server. In my map file I have
> >
> > IMAGEPATH "c://mapserver_temp//"
> > IMAGEURL "temp"
> >
> > How does the image url know to point to the image path? I suppose I
> need
> > to create some kind of alias that maps "temp" to "c:/mapserver_temp"
> but
> > I don't know how to do this? Can anyone offer some help please?
> >
> > Thanks
> > Nelson
> >
> > Disclaimer :
> > The contents of this e-mail including any attachments are intended
> only
> > for the person or entity to which this e-mail is addressed.  If you
> are not,
> > or believe you may not be, the intended recipient, please advise the
> sender
> > immediately by return e-mail, delete this e-mail and destroy any
> copies.
> > Tenix does not warrant nor guarantee that this email communication is
> free
> > from errors, virus, interception or interference.
> >
> >
> When I ran mapserver and tomcat together on a mac platform,  I said
> things like
>
>
>   TEMPLATE ../WEB-INF/post_transform_directory/en-gb/mob_resources.xml
>   IMAGEPATH "../tmp/"
>   IMAGEURL "tmp/"
>   LOG "/tmp/map.out"
>
> I can't comment on the window platform to much, but I suspect that
> saying
>
> IMAGEPATH "c:\\mapserver_temp\\"
> IMAGEURL "temp"
> may help, or perhaps justing using \ instead.
>
> TO a java program a file seperator is / or \, but mapserver is a C
> program, so it may choose only to understand the \ character.
>
> D.
>
>
>
>
>
>
>
> Disclaimer :
> The contents of this e-mail including any attachments are intended only
> for the person or entity to which this e-mail is addressed.  If you are not,
> or believe you may not be, the intended recipient, please advise the sender
> immediately by return e-mail, delete this e-mail and destroy any copies.
> Tenix does not warrant nor guarantee that this email communication is free
> from errors, virus, interception or interference.
>



More information about the mapserver-users mailing list