Link to home
Start Free TrialLog in
Avatar of Jasbir21
Jasbir21

asked on

Updates and images displayed on coordinates

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



Avatar of jimmack
jimmack

>> 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?
Avatar of Jasbir21

ASKER

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
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?
...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



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
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.
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
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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
>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 ;-)

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
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>


>> prep1.executeUpdate();

should be:

prep1.executeUpdate(s);

You weren't including the statement to execute ;-)
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);
Oops ;-)  You're right JNic.  Sorry, I've only just woken up ;-)

Are any exceptions being raised or errors output to the log files?
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
And good morning to jimmack :-D      - been there, done that!! ;-)
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
   
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 :-)
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
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")+"'>
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
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


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

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
hi, i divided the points equally ,

thanks