Solved

Updates and images displayed on coordinates

Posted on 2003-11-16
28
516 Views
Last Modified: 2010-04-01
hi,
  i have a form like this:
<html>
<head><title> Adding update</title>
<style type="text/css"> <!-- .inputimage { background-image: url((URL))} --> </style>
</head>
<body>

Image  :


<body bgcolor="#FFFFFF" text="#000000">
 <form name="form1" method="post" action="" enctype="multipart/form-data">
 <input type="file" name="file" class="inputimage">

</p>
Update :
<textarea type="text" name="desc" rows="5" cols="15" wrap>
</textarea>
</p>

<input type=button value="Add" > </p>
</form>
</body>
</html>

This form would be used to browse the image and select it and add update information.

The images and update information needs to be displayed in another form menu.jsp (which i don't know how to do)

at the exact coordinates.

I mean something like this:

Update information

Image 1 update info        |      Image 2 update info

Image 3 update infor       |     Image 4 update info

Information.


Thanks



0
Comment
Question by:Jasbir21
  • 13
  • 9
  • 3
  • +2
28 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9760540
>> at the exact coordinates

What do you mean exact coordinates?  If you want the images to be displayed in a nicely formatted way, can't you just put them into a table?

Is your problem with this page or with the menu.jsp page?
0
 

Author Comment

by:Jasbir21
ID: 9760642
hi,
   my problem is with menu.jsp which i don't know how to do,but you would need this page to add image or update at menu.jsp.For i would need to use this page to add the image each time at menu.jsp

What do you mean exact coordinates? Actually i mean in a formatted way, i mean how do you do it to say i need update at this line.or picture at this line.(of course the update and image gets stored at database.

The menu.jsp is the page which has updates which needs to be updated frequently



Thanks
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 9762031
hm...i can't understand:
 you have all your info and images stored in DB? right?

if so, get it from DB, insert into your page and that's all, what's trouble?
0
 

Author Comment

by:Jasbir21
ID: 9762389
...hi,
   i guess i am confusing things sorry....

LEts say i have images called oren.gif,epal.gif,banna.gif,pine.gif

The update for oren.gif is the oren is as   .....
The update for epal.gif is the epal is ....
the update for pine.gif is .....

Lets says at first it is like this:

Title : the fruits are...

oren.gif is the oren             | epal.gif is the epal...

pine.gif is ..................      | etc...


How to do it so that the admin uses menu.gif to browse for images , and insert into database, of course and the update in database

But it needs to be displayed in menu.jsp like above.

But lets say the next day, the images and displayed must be changed, how do i do all that?

I hope i am not confusing things.
thanks



0
 
LVL 1

Expert Comment

by:JNic
ID: 9763510
It is actually quite hard to understand your question, but I will give it a shot. Then we maybe have to narrow it down later. I imagine you have table in your db looking something like this:

pictures
---------
name
path
info

Then in your menu.jsp get a ResultSet :

<%
String query="select * from pictures";
ResultSet rs = statement.executeQuery(query); // assuming you have a connection and statement
// now we build a table
out.println("<table>");
while (rs.next()){
   out.println("<tr><td><img src='"+rs.getString("path")+"'></td><td>"+
                   "<textarea name='"+rs.getString("name")+"' rows="5" cols="15" wrap>"+rs.getString("info")+
                   "</textarea></td></tr>";
                   // in the img src you can add "width=100 and height=200" to adjust image size
}
out.println("</table>");
%>

If this does not help you, please post excactly how your db-table looks like, and also post all jsp
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9765136
I believe you have image column and imformation column in your database. you'll also need an ID column added to your table, for example:

ID    Image      Information
--------------------------------
1     oren.gif     is the oren
2     epal.gif     is the epal...
3     pine.gif     is ...

You should then include a new ID hidden field in the edit page.
then for the new images, you leave id=0, so you know you need to insert. for existing image, you simple update by id.

let me know if you have further enquires.
0
 

Author Comment

by:Jasbir21
ID: 9766973
hi,
->  please post excactly how your db-table looks like, and also post all jsp

 currently my table is like this:

create table picture(information varchar(60),image varchar(20));

JNIc, i have done nothing for menu.jsp because i don't know how to do it.
Do i need the path variable ?

kennethxu,
->you leave id=0, so you know you need to insert. for existing image, you simple update by id.
i did n't understand the part of hidden input.


Sorry for confusing things. It is something like this : my teacher feels that it is very tedious if a user would have to change the menu.jsp images or information explicitly(hard coded).
So, she wants something where a user could use a form to change the menu.jsp.
I really hope i am not confusing.Pls ask me if i am .

Thanks
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 232 total points
ID: 9767535
I didn't mean that you should do it manually, the id should be the key that you use in your code and it is hidden from user.

the id should be used to distinguish which image is which, isn't that what you are wondering about?

I think the menu.jsp is the page that user browser for all his images.

the first time he come to this page, there is no image on it, so he click "add" link, which opens your addedit.jsp page (the one you posted) with id=0 (addedit.jsp?id=0)

user submits the addedit.jsp page, a new record is added to database and you'll assign id=1 to that new record. then user is redirect to the menu.jsp, this time menu.jsp will display the first image.

the id increases when you add more image to database.

there should be an edit link sitting in the side of the image. the link should be addedit.jsp?id=1 for the first image and then addedit.jsp?id=2 for the 2nd image and etc.

when user click on edit link, you addedit.jsp will receive the id of the image that user want to edit, you can then update the database with the information user entered in you addedit.jsp page.

I'm not writing to code for you because I think you should do your assignment and learn something from here.

HTH
0
 
LVL 1

Expert Comment

by:JNic
ID: 9767586

Oh, I think I got it wrong! I thought you wanted to DISPLAY the pictures, - but now I understand you just want to show the names of the pics with the information. Then forget my last post :-(

I would like to get clarified what you want. Copy the following into an empty text file, and store it as "test.html":

<html>
<head><title>Menu</title>
</head>
<body>
<form action="update.jsp">
<table>
<tr><td>oren.gif</td><td>is the oren</td><td><input type="submit" value="update"></td>
<td>orange.gif</td><td>is an orange</td><td><input type="submit" value="update"></td></tr>
<tr><td>epal.gif</td><td>is the epal</td><td><input type="submit" value="update"></td><td>appel.gif</td><td>Is a very nice apple</td><td><input type="submit" value="update"></td></tr>
<tr><td>pine.gif</td><td>is the pine</td><td><input type="submit" value="update"></td><td>pear.gif</td>
<td>This is my favorite fruit</td><td><input type="submit" value="update"></td></tr>
</table>
</body>
</html>

Just tell me, if this looks like what you want or not. If it does, then I (or Kennethxu) will help you achieving it.

Regards,

Nic
0
 
LVL 1

Expert Comment

by:JNic
ID: 9767599
>I'm not writing to code for you because I think you should do your assignment and learn something from here.

Listen to kennethxu, he is a clever man ;-)
0
 

Author Comment

by:Jasbir21
ID: 9768696

kennethxu and JNic, i guess you are right, i should learn..i mean, you spent a lot of time writing to explain it to me how to do it,
i think i understand, pls give me a bit time, i am trying.

thanks
0
 

Author Comment

by:Jasbir21
ID: 9769450
hi,
  I am trying and this is what i got so far,
for addedit.jsp : i found out the image is not inserting into the database or other values

the current picture table is :
id -varchar(10)
updates -varchar(60)
image-blob


<html>
<head><title> Adding update</title>
<style type="text/css"> <!-- .inputimage { background-image: url((URL))} --> </style>
</head>
<body>

Image  :


<%@ page import="java.sql.*"%>

<body bgcolor="#FFFFFF" text="#000000">

<%

//***Declaration of variables...
      String connectionURL = "jdbc:mysql://localhost:3306/mydatabase?user=;password=";
      Connection connection = null;
      Statement statement = null;
      PreparedStatement prep1,prep2;
      prep1=null;
      prep2=null;
      ResultSet rs = null;

 try
      {

     //***loading the jdbc driver...  
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     connection = DriverManager.getConnection(connectionURL, "", "");
     statement=connection.createStatement();
     
     
    String id=request.getParameter("id");
    String updates=request.getParameter("updates");
    String image=request.getParameter("file");
 
   String s="insert into picture(id,updates,image) values(?,?,?)";
   
   prep1=connection.prepareStatement(s);
   
   prep1.setString(1,id);
   prep1.setString(2,updates);
   prep1.setString(3,image);
   prep1.executeUpdate();
   prep1.close();

}

catch( SQLException ex )
{
   ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
   ex.printStackTrace() ;
}



%>
 <form name="form1" method="post" action="addedit.jsp" enctype="multipart/form-data">
<input type="hidden" name="id" value="0">
 <input type="file" name="file" class="inputimage">
</p>
Update :
<textarea type="text" name="desc" rows="5" cols="15" wrap>
</textarea>
</p>
<input type=button value="Add" > </p>
</form>

</body>
</html>


0
 
LVL 15

Expert Comment

by:jimmack
ID: 9769920
>> prep1.executeUpdate();

should be:

prep1.executeUpdate(s);

You weren't including the statement to execute ;-)
0
 
LVL 1

Expert Comment

by:JNic
ID: 9770001
Eh, jimmack - I think the code was allright - this is a prepared statement:

>String s="insert into picture(id,updates,image) values(?,?,?)";
>prep1=connection.prepareStatement(s);
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Expert Comment

by:jimmack
ID: 9770033
Oops ;-)  You're right JNic.  Sorry, I've only just woken up ;-)

Are any exceptions being raised or errors output to the log files?
0
 
LVL 1

Expert Comment

by:JNic
ID: 9770054
Hi Jasbir, your code looks nice! - Well done!

There are no errors in your java code (as far as I can tell).

First I have a few suggestions to your table: id should be an int and set it to AUTO_INCREMENT. This way, every time you insert something new into the table, it will automatically insert a new id=highest value+1. If you do this, you should change this :

String s="insert into picture(id,updates,image) values(?,?,?)";
prep1=connection.prepareStatement(s);
prep1.setString(1,id);
prep1.setString(2,updates);
prep1.setString(3,image);

to this:

String s="insert into picture(updates,image) values(?,?)";
prep1=connection.prepareStatement(s);
prep1.setString(1,updates);
prep1.setString(2,image);

But as mentioned you id must be an int, and set to AUTO_INCREMENT. - If you would like a nice administrative tool for mysql, try out mysqlcc at http://www.mysql.com/downloads/mysqlcc.html

Also, I am not sure why you save image as blob. Blob if a datatype which is normally used to save big files, like fx pictures, but if you only want to store the filename a varchar is fine.

Maybe the error is the text-area. The name should be "updates" :

<textarea type="text" name="updates" rows="5" cols="15" wrap>
</textarea>

You have build this page in a way, so that you will always stay on it, since the form-action="addedit.jsp", - maybe you do this for testing-purposes, but later on it should of course lead to menu.jsp.

Let us know how you make progress.
Regards,

Nic
0
 
LVL 1

Expert Comment

by:JNic
ID: 9770059
And good morning to jimmack :-D      - been there, done that!! ;-)
0
 

Author Comment

by:Jasbir21
ID: 9770294
JNic,
   Actually i am saving a gif image and not a filename.Previously, i made a mistake by creating a database of varchar for image to store a gif image.

Is there anything else  to use to store gif pictures...

Thanks
   
0
 
LVL 1

Expert Comment

by:JNic
ID: 9770343
No, its fine with blob then :-)
But saving a picture to a db is a bit more complicated. - It is certainly possible and has been done, but I have never tried it - so I cant help you further on that topic. But the approach to store the path/filename in the db is also good, - I think it performes better also.
Anyone with more knowledge is welcome to disagree with me :-)
0
 

Author Comment

by:Jasbir21
ID: 9770416
ok, i guess i would change to path then , wouldn't want complicated things ..is the approach for path/filename much much different, how do you do it?

Thanks
0
 
LVL 1

Expert Comment

by:JNic
ID: 9771810
Well, very simply the way I suggested, that you store the filename instead of the picture. You can choose to add the path to your table also, but you can also just work with the same path for your pictures always.
An example HTML that displays a picture looks like this:
<img src='c:/pictures/oren.gif'>
- You can also set width and height of pic like this: <img src='c:/pictures/oren.gif' width=300 height=200>
So your code could be:
<img src='"+rs.getString("image")+"'>
0
 

Author Comment

by:Jasbir21
ID: 9776800
hi, I don't know why empty result strings are getting entered.I mean data is not getting entered at all.



<%@ page import="java.sql.*,com.dhal.*"%>

<jsp:useBean id="ad" class="com.dhal.admin" scope="session"/>
<jsp:setProperty name="ad" property="*"/>


<html>
<head><title> Adding update</title>
<style type="text/css"> <!-- .inputimage { background-image: url((URL))} --> </style>
</head>
<body>

Image  :



<body bgcolor="#FFFFFF" text="#000000">

<%

//***Declaration of variables...
      String connectionURL = "jdbc:mysql://localhost:3306/mydatabase?user=;password=";
      Connection connection = null;
      Statement statement = null;
      PreparedStatement prep1,prep2;
      prep1=null;
      prep2=null;
     
 try
      {

     //***loading the jdbc driver...  
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     connection = DriverManager.getConnection(connectionURL, "", "");
         
 
    String updates=ad.getUpdates();

    System.out.println(updates);

    String path=ad.getPath();
   
 
   String s="insert into picture(path,updates) values(?,?)";
   
   prep1=connection.prepareStatement(s);
   
   prep1.setString(1,path);
   prep1.setString(2,updates);
      prep1.executeUpdate();
   prep1.close();

String ta=request.getParameter("ta");
System.out.println(ta);
}

catch( SQLException ex )
{
   ex.printStackTrace() ;
}
catch( ClassNotFoundException ex )
{
   ex.printStackTrace() ;
}



%>
 <form name="form1" method="post" action="addedit.jsp" enctype="multipart/form-data">
 <input type="file" name="path" class="inputimage">
</p>
Update :
<textarea type="text" name="updates" rows="5" cols="15" wrap>
</textarea>
</p>

<input type=submit value="Add" > </p>

</form>
</body>
</html>


Pls see and thansk
0
 

Author Comment

by:Jasbir21
ID: 9776929
hi, i found my error, i am so glad i used the path and the image actually gets displayed.i am happy .i am still working on it but i would post my progress, so pls look at this question.

thanks


0
 

Author Comment

by:Jasbir21
ID: 9776939
my current problem is when i put :

String myquery="select * from picture"; all pictures gets displayed but i don't want that, how do i do

0
 

Author Comment

by:Jasbir21
ID: 9777642
i mean i need the  picture on the left and right and not like that


Image 1 update info        |      Image 2 update info

Image 3 update infor       |     Image 4 update info

thanks
0
 
LVL 1

Assisted Solution

by:JNic
JNic earned 233 total points
ID: 9778118
Hi Jasbir,

Im glad you are making progress! :-)

I think you should consider to close this question soon, since there allready has been a lot of problems discussed and solved. Also remember that all people that answered this thread (me, kennethxu, dualsoul and jimmack) are receiving e-mails each time you write a new comment.

It is a good thing to stick to one question per thread, since other people can easier find answers to questions. I mean,  we have now have been talking about a ways of storing pictures in a database, - it is quite impossible for other people to guess that this problem is discussed in a thread called :"Updates and images displayed on coordinates"

About your problems: Take a look at this html-page (copy and paste it into an empty text-file, close and save it as test.html, and doubleclick on the new file.) (I posted this earlier allready).

<html>
<head><title>Menu</title>
</head>
<body>
<form action="update.jsp">
<table>
<tr><td>oren.gif</td><td>is the oren</td><td><input type="submit" value="update"></td>
<td>orange.gif</td><td>is an orange</td><td><input type="submit" value="update"></td></tr>
<tr><td>epal.gif</td><td>is the epal</td><td><input type="submit" value="update"></td><td>appel.gif</td><td>Is a very nice apple</td><td><input type="submit" value="update"></td></tr>
<tr><td>pine.gif</td><td>is the pine</td><td><input type="submit" value="update"></td><td>pear.gif</td>
<td>This is my favorite fruit</td><td><input type="submit" value="update"></td></tr>
</table>
</body>
</html>

Here elements are put in a table to control their positioning. Try and replace the "*.gif" with <img src='*.gif'> so that pictures are displayed.  Study it closely and make sure you understand how a table works. (seek info on google if you need it - search: HTML TABLE).

When you understand this, the next step will be to construct a table from your jsp with excactly the pictures and information you want. For an idea of how to do this, look at my very first post in this thread.

I wish you good luck - I will be leaving my computer for  a week now, but there are plenty of people here that can help you. But remember to go as far as possible on your own on each question. And if you agree that it is time to close this thread, I think points should be split between kennethxu and myself.

Kind regards,

Nic
0
 

Author Comment

by:Jasbir21
ID: 9786166
thanks...i think its time to close the question...I guess, the heading was wrong,
thanks all of you for being understanding and helping me out.....

Thanks
0
 

Author Comment

by:Jasbir21
ID: 9786204
hi, i divided the points equally ,

thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
difference between member and local variables. 29 122
String format issue 13 88
struts spring hibernate example 12 86
Java Script nested call 3 55
In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now