How do you inserst images with java on a web page?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How do you inserst images with java on a web page?

  1. #1
    Join Date
    Nov 2005
    Posts
    2

    Question How do you inserst images with java on a web page?

    Hey,

    I am trying to make my web page load a different image depending on the screen resolution that you are viewing the page with.

    I currently have a seperate page that has java code to redirect to a different web page depending on the resolution of the computer viewing the page. I have decided it would be more practicle if there was no redirecting page and there was just one page that had different images load depending on the screen resolution.

    My code i was using for the page redirect is below.

    Can this code be implemented on a web page so a different image loads depending on the screen resolution?

    I dont know the java commands to load an image onto the screen or if it is even as easy as i think it is.

    Also how can i make it so the images load in a certain place on the screen?

    The website i am trying to make this work on is below. Check it out to see how my current code works. I would like to cange it so the main image is larger on higher resolution computers and smaller on low resolution ones.

    http://members.shaw.ca/t-steele
    or
    http://www.cordovabayvacationsvictoria.com

    the index file redirects you to either main2.html or main3.html.

    I want to get rid of the main pages and just have an index that takes care of screen resolution issues.

    Any help would be much appreciated.

    Thanks for the help. Coding is below.


    <script language="JavaScript">

    if (window.screen){
    var w = screen.width;
    tmt_url_800 = "main2.html";
    tmt_url_1024 = "main3.html";

    if(w<740){
    self.location.replace(tmt_url_800);
    }

    if(w>=740 & w<835){
    self.location.replace(tmt_url_800);
    }

    if(w>=835){
    self.location.replace(tmt_url_1024);
    }

    }//tmtC_resolutionRedirectEnd
    </script>

  2. #2
    Join Date
    Jul 2005
    Location
    Antwerp - Belgium
    Posts
    29

    javascript or java ?

    You're showing us a javascript program, which has nothing to do with java. If you want a java example, let me know. I can provide an example. If it's in javascript that you want the solution, you should look for the right forum.

  3. #3
    Join Date
    Nov 2005
    Posts
    2

    i didnt know they were different

    ... sorry, i guessed i was confused and i didnt know there was a difference between java and javascript. what is the difference? thanks for the heads up.

    a solution in java or java script would be just fine, so if you could provide one in java that would be great.

    Thanks.

  4. #4
    Join Date
    Jul 2005
    Location
    Antwerp - Belgium
    Posts
    29

    java compared to javascript

    Don't worry : you're not the only one who gets confused about java or javascript.

    Javascript is considered being a scripting language which is confined to the borders of the HTML-page where the script is written. In other words, you can control a whole HTML page but not what is outside of this page, like a database.

    Java is an object-oriented programming language, which has elements of syntax and semantics in common with the C-family (C, C++, C#). You can build whole applications using java and you can write JSP's or Java Server Pages which produce HTML-pages.

    If you want to write a web application in java, you should learn about the MVC or Model-View-Controller design pattern. This pattern divides a java web application in javabeans, servlets and JSP's.

    Just to give you a feeling of how a java program looks like, I'll add some code which gets a BLOB or binary large object out of a database and displays it. The BLOB in fact is a GIF or JPG from the database.


    Code:
    	private void toonBlob (HttpServletResponse _response, Blob _beeld)
    		throws SQLException, IOException 
    	{
    		byte[] blobBytesArray = null;
    		OutputStream stream = _response.getOutputStream(); 
    		Logger gcoLogger = Logger.getLogger("gco.log");	
    		if (_beeld != null)
    		{
    			try {
    				int len = new Integer( new Long( _beeld.length()).toString() ).intValue();
    				blobBytesArray = _beeld.getBytes(1,len);
    				if (blobBytesArray != null)
    				{
    					gcoLogger.debug("imageservlet - blob <> null ");  
    					if (blobBytesArray.length > 0 )
    					{
    					gcoLogger.debug("imageservlet - blob.length > 0 ");  	
    					stream.write(blobBytesArray);
    					}
    	    	
    				} /* blobBytesArray != null */
    				
    			} catch (SQLException sqlEx)
    			{
    				throw sqlEx; 
    			}
    			  catch (IOException ioEx)
    			  {
    			  	throw ioEx;
    			  }
    			
    		} /* _beeld != null */ 
    		
    	} /* toonBlob () */
    If you want more information about this, let me know.
    But for your problem, I've got the feeling the solution should be found
    in javascript. But since my knowledge of javascript is very restricted, I cannot help you. Look for a javascript forum.

Similar Threads

  1. Grabbing Paramaters from a web page.
    By gjon in forum Java
    Replies: 2
    Last Post: 10-30-2005, 10:34 AM
  2. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM
  3. need your help
    By rachel in forum Java
    Replies: 0
    Last Post: 07-05-2000, 12:34 PM
  4. Replies: 1
    Last Post: 04-06-2000, 05:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center