It's already the third time that i post the same question, please help me!

I am writing a simple guestbook that is able to insert and fetch text and image from database and display them. There is a html that forms the parameters to this servlet, some text information such as "name", "address" and one picture. Insertion and fetching of text and images works sepearately, but when i combine them there is a conflict between "doGet" and "doPost". My text insertion only works with "doGet" (don't know why, but when i type "doPost" it does not work) while image insertion only works with "doPost" since i am using "Multipartrequest" to read the image.
Since i write "doGet" in my code, the exception is following
java.io.IOException: Posted content type isn't multipart/form-data
SQLB.doGet(SQLB.java:42)Following are the codes , please give me a hand, many thanks!!
the problem line that causes exception is marked with ////////////////////////////////// above in red color
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.awt.image.*;
import com.oreilly.servlet.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.oreilly.servlet.ServletUtils;
import java.net.*;
import java.sql.*;
public class SQLB extends HttpServlet{
    Connection con;
    PreparedStatement pstmt=null;
    public void init(){
     //connection need url, username and password
     String url="jdbc:mysql://atlas.dsv.su.se/db_5974722";
     try{
         new com.mysql.jdbc.Driver();
         con = DriverManager.getConnection(url, "usr_5974722", "974722");
     }catch (Exception ex){}
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException, ServletException{
     //get the text fields information     
     String namn=req.getParameter("namn");
     String epost=req.getParameter("epost");
     String hemsida=req.getParameter("hemsida");
     String kommentSQLB.doGet(SQLB.java:42)ar=req.getParameter("kommentar");
     //get the pic as file
     MultipartRequest mreq=null;
     PreparedStatement pstmt1=null;
     PreparedStatement pstmt2=null;
     res.setContentType("text/html");
     String mime=null;
     File file=null;
     File dir = (File)getServletContext().getAttribute("javax.servlet.context.tempdir");
     mreq = new MultipartRequest(req, dir.getAbsolutePath(), 5000000);
     mime= mreq.getContentType("file");     
     file = mreq.getFile("file");
     Statement stmt=null;
     ResultSet rs=null;     
     //first save all the information to the database
     //then go through it and print out all the content
     //both tables have id as key
     try{
         new com.mysql.jdbc.Driver();
         //save the picture
         pstmt2 = con.prepareStatement("INSERT INTO picture(p,type) VALUES ( ?, ?)");
         FileInputStream fis = new FileInputStream(file);
         byte[] data=new byte[(int) file.length()];
         fis.read(data);
         fis.close();
         pstmt2.clearParameters();
         pstmt2.setBytes(1, data);
         //another way to insert blob
         //pstmt2.setBinaryStream(3,fis, (int)file.length());
         pstmt2.setString(2,mime);
         pstmt2.execute();
         //picture saving done
         //save other text information
         pstmt = con.prepareStatement("INSERT INTO guestbook (NAME,TIME,EPOST,HEMSIDA,KOMMENTAR) VALUES(?,?,?,?,?)");
         pstmt.clearParameters();
         pstmt.setString(1,namn);
         pstmt.setString(2,new java.util.Date().toString());
         pstmt.setString(3,epost);
         pstmt.setString(4,hemsida);
         pstmt.setString(5,kommentar);
         pstmt.execute();
         //text informatin saving done
         //pstmt1=con.prepareStatement("DELETE FROM picture");
         //pstmt1.execute();
         //print the guestbook information and invoke the SQLC servlet
         //to display picture
         String queryprint="SELECT * FROM guestbook";
         rs=pstmt.executeQuery(queryprint);
         PrintWriter out=res.getWriter();
         out.println("<HTML><HEAD><TITLE>guestbook</TITLE></HEAD>");
         out.println("<BODY>");
         while ( rs.next() ) {
          String name = rs.getString("id");
          out.println("TID:  "+ rs.getString("TIME"));
          out.println("<br>");
          out.println("FR�N: ");
          out.println("<a href=\"rs.getString(HEMSIDA)\">"+rs.getString("NAME")+"</a>");
          out.println("<br>");
          out.println("e-post");
          out.println("<a href=\"mailto:"+rs.getString("EPOST")+"\">"+rs.getString("EPOST")+"</a>");
          out.println("<br>");
          out.println("Kommentar:  "+rs.getString("KOMMENTAR"));
          out.println("<br><br><br>");
          out.println("<br>");
          out.println("<img src=\"http://localhost:8080/ip/servlet/SQLC?id=" + name+ "\">");
         out.println("</body>");
         out.println("</html>");
            rs.close();
         pstmt.close();
            con.close();
     catch (Exception e){
         e.printStackTrace();
}

do you send the mulitipart MIME type like this ?
<FORM action="youraction"
       enctype="multipart/form-data"
       method="post">

Similar Messages

  • This is the third time I am posting this "easy" question...

    How do I get a JSpinner to display 01 instead of 1. I have a JSpinner to display minutes i.e. 0-59 that user uses for my time control.

    import java.util.*;
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    public class Test extends Applet {
         JSpinner sp;
         String[] seconds;
         public void init(){
              seconds = new String[60];
              for (int i = 0; i < 60; i++)
                   seconds[i] = i < 10 ? new String("0" + i) : new String("" + i);
              sp = new JSpinner(new SpinnerListModel(Arrays.asList(seconds)));
              sp.setPreferredSize(new Dimension(100,30));
              add(sp);
    };

  • I have one  iphone 4s is the third time that sends Ai repairs .. not my substitutions with a new record even if I have no guarantee I replace it with a new one I'm tired of this story what I can do;;

    I have one is the third time that you send for repair .. not my substitutions with a new record even if I guarantee I'm tired of this story what I can do;;; For two months I have not mobile .. every ten days sends it to my dealer and sends it exactly as you send it back .. and no problems have been made ... find my solution;;

    The people responding in this forum are just other Apple product users like you, not Apple itself.  Apple Support Communities is primarily an end-user to end-user (i.e., users like you helping other users) technical issue support feature.
    Try:
    Contact Us

  • Hi!  I cant conect The face time betwen my iPad ,iPod and iPhone, please help me,what i need for this issue?

    Hi!  I cant conect The face time betwen my iPad ,iPod and iPhone, please help me,what i need for this issue?

    What is it doing when you try to facetime? also if you are using the same apple Id/email on each device, it wont work.

  • What is the certification authority, the third party that can confirm the digital signature?

    I created a nice electronic signature, that I now regularly use and add to every document. I was told that a signature needs to be issued by a verification authority, a third party that is able to verify the signature, certificate. I created a free certificate at CAcert.org and tried to combine it with the adobe signature certificate file, but it doesnt support .cer and .crt files. Is the Adobe the certification authority in this case since i created signature in the Adobe software? Its not a big deal, I just want everything to be correct since I use the signature in official documents now (instead of scanning a signed document) ... Thanks for any info, ideas or help.
    Jacob

    Each Digital Certificate has a pair of private and public keys used for encryption/decryption. The private key belongs to the certificate owner and should be kept secret. It is protected by a password. The public key can be used by anyone. Digital certificates come in two flavors: one that contains both private and public key and one that contains only public key.
    When you create a digital signature the signing process uses the private key to encrypt the signed content digest and the public key is used to decrypt it. So, only you can encrypt signed content with your certificate that has both private and private keys and anyone can decrypt it to validate the signature using certificate that has only public key. Usually, this certificate with the public key only is embedded in the digital signature, so that anyone can use it for decryption.
    The .cer certificate contains only public key. Certificates with both private and public keys usually have extensions .pfx or .p12. You need one of those to sign.
    CAcert.org issues only public key certificates. so you cannot use its certificates for digital signing.
    Adobe is not a general purpose certification authority. It issues some certificates for internal use only.
    Acrobat has a feature that allows you to create so-called self-signed certificates with both private and public keys but these certificates can be used only in a limited way. They do not provide the means to authenticate the real certificate owner nor revoke a certificate if it is stolen.
    Generally, a digital signature asserts three main features:
    1. Document integrity (document has not been changes since it had been signed),
    2. Authentication (the signer is indeed what the certificate says)
    3. Non-repudiation (the signature author cannot deny that he signed it: this is achieved via certificate revocation mechanism).
    A self-signed certificate (of the type that Acrobat produces) can be used only for #1. It cannot be used for ##2 and 3. The latter two come only when a certificate (with private key) is issued by a reputable Certificate Authority which is trusted (like VeriSign, Symantec, etc.).

  • I have moved from the US to Norway, and want to change my apple ID to the Norwegian appstore. However, I am not allowed ot change from the US store before I use up my balance, which is 0.17 dollar. The problem is that nothing costs 0.17 dollar.Please help

    I have moved from the US to Norway, and want to change my apple ID to the Norwegian appstore. However, I am not allowed ot change from the US store before I use up my balance, which is 0.17 dollar. The problem is that nothing costs 0.17 dollar and I do no longer have an american visa card, only Norwegian. Is there any way I can erase the credit on my account so I can change the appstore country? Or osmething I can use this credit on? Thank you very much

    Try contacting the store support staff at: http://www.apple.com/emea/support/itunes/contact.html they are usually pretty good at sorting out these issues.

  • Can't access Facebook on my iPad mini. When ever I try to login, it says go to settings.. And in setting I am asked to renter the password, after that nothing happens on screen. Please help.

    I am unable to access my Facebook account on iPad mini. When ever I try to login, it says go to setting and there i am asked to renter the password. After entering the password nothing happens, neither the option of done gets activated and nor anything happens automatically.
    But when I press the return button, it says that "Error: we are unable to connect to sever".
    Please help.

    Problem solved
    Visit the below URL to solve the problem: http://howtoapple.com/facebook-login-issues-ios-7/

  • HT202159 I am unable to download and always asking password after entering the password  also asking same question please help  me to sort out  this problem.

    I am unable to download and always asking the password it's ok for the once and it's asking more and no results only repeating the same so I am unable to download please help me to sort out this problem and my request please sort out from your side  or let me guide .

    Thanks Eric for responding.
    I checked and it does not appear in the Applications folder.
    I tried yesterday on an ethernet connection with a download speed of 2 Mbps but, unfortunately the connection died(It happened from the ISP end, which is out of my control) in between after which there was no trace of the download that happened for so long(till the internet connection death). 
    One more serious query which I am unable to understand. If the internet connection, dies in the midst of the download is in progress why is it so that the state does not persist and one has to restart the entire process again. Is there no solution for this?
    I tried so many times and its the same case after some amount of download it vanishes. So many unsuccessful attempts. I am ****** off now. Is it not possible to see Mavericks? Why does different machines of Apple behave differently? Somewhere it goes smoothly and somewhere like my mine. Why did not Apple release a non apple store version? Is this not a bad sign of letting the users struggle when something is being offered for free?
    The reason I asked as whether we can download the .app of Mavericks is that, there are so many applications that I have downloaded web and have installed. All that works fine. Can't we do the same here? You download a copy of Mavericks installer application and upload it for me in Google drive or like online storage places which can be downloaded and used by me? Help me understand.
    Thanks again.

  • This is the third time i'm asking the same questio...

    My mobile nokia c2-01. Nokia store is not working and in store.ovi.mobi my device is not recognised.

    If restarting the app or your iPad/iPhone does not work, we are not aware of any other ways to fix this particular problem.  Uninstalling & reinstalling Adobe Reader may be the only option left.  It will clean up the "inconsistent" application data.  But it is not even guaranteed to fix the problem.
    If you uninstall Adobe Reader (or any other iOS apps), iOS will erase all of the application data including settings/preferences and PDF documents stored locally on your iPad/iPhone.
    We'd highly recommend backing up your PDF documents regularly (not just this time) so that you do not lose them when something goes wrong.
    How to backup and restore PDF documents on your iPad/iPhone using iTunes
    Backup your PDF documents.
    Uninstall Adobe Reader.
    Download and reinstall Adobe Reader from the App Store.
    Alternatively, you can store your PDF documents in cloud storage (e.g. Acrobat.com, Dropbox, Google Drive), which will eliminate the need to backup local files.
    Please let us know if you need further assistance.

  • My apps on my ipod touch wont open! Whats up with that? They were just working a few days back. The only thing that opens is my music. Please help!!!!!

    Is anyone out there? I need help a.s.a.p!

    Have you tried a hard reset of your iPod to see if that makes a difference?  To do this, press and hold both the Sleep/Wake and Home buttons together long enough for the Apple logo to appear.
    B-rock

  • How do i install my Adobe Creative Suit 6 Design Standard to the new iMac that has no disc drive? Please help!

    The new iMac has no disc drive so how on earth am i supposed to download/install my CS6 disc?

    Download it from http://prodesigntools.com/adobe-cs6-direct-download-links.html
    Make sure you follow the Very Important Instructions on that page.

  • Iam posting this for third time but nobody is giving any reply: Please help

    One of our user created an ACH file and sent it to the bank for payment.He created this ACH file in one bank but by mistake sent it to other bank for payment.The payment has been cleared . Because of this my bank balances have changed. Could anyone help me to resolve this issue so that all my bank balances are set.Please give suggestions as early as possible . I will assign you points.Thanks in advance.

    Hi Kavitha,
    Reset and reverse the payment documents in FB08.
    And again run the payment run by selecting right bank
    ~Rajesh

  • Can anyone recommend an external storage device to supplement my mac book air?  I already have a time capsule but want the new device to replicate the data on that so ideally would like a device that i can connect to the time capsule through a cable.

    Can anyone recommend an external storage device to supplement my mac book air?  I already have a time capsule but want the new device to replicate the data on that so ideally would like a device that i can connect to the time capsule through a cable. 

    Hi CJR
    I'm not sure how Time Capsule can be replicated onto your external drive but there is a USB port on the back of TC that can be hooked up to any recent external drive.
    Another thing to think about , besides a Time Capsule failure, is the theft of your Time Capsule, so it might be a good idea to consider separating any redundant back-up from your Time Capsule or both my be stolen.
    TC will back up until full and then begin deleting the oldest back-ups.  Mine is a 2TB Time capsule.
    My back-up plan is as follows:
    1.  Macbook Air back-up on Time Capsule though Time Machine backs up everything - I think it's about every 30 min or so.
    2.  Contacts, reminders, appointments, notes, email are backed up through iCloud.
    3.  iTunes and non-itunes purchased music is on iMatch (and no need to back-up) and any non-iTunes music is backed up on an HP external drive (in case Time Capsule dies)
    4.  Photos are on my MacBook Air and are backed up on my HP external drive.
    5.  Office documents (Excel, Powerpoint, Access etc) are stored in a Skydrive app (like iCloud) and Skydrive syncs these docuemnts with the MS  cloud and my old PC and does not alter their native format like storing in iCloud would do.
    Cheers

  • How to correct the error message that appears when installing photoshop CS5 for the third time

    I need help so solve the error message that appears on my computer when I try to register the program for the third time. Please helpppppp!

    If you're referring to the activations warning, simply call support to reset them.
    Mylenium

  • I ask the third time: How can I enlarge the menue symbols and the text of the menue in Photoshop CS6 vers.13 so that I can read them??? My laptop has Win 8.1 and a screen resolution of 3840x2160

    I ask the third time:
    How can I enlarge the menue symbols and the text of the menue in Photoshop CS6 vers.13 so that I can read them??? My laptop has Win 8.1 and a screen resolution of 3840x2160.
    It is unbelievable that such an expensive software does not provide a proper lay out wit a high screen resolution!
    It is also unbelivable that it is not possible to get a qualified employee of ADOBE on the phone in Germany.
    hope of feed back: e-mail: [email protected]

    Chris Cox answered your question here:
    I have PS cs6 extended and a new laptop with screen resolution of 3840x2160. Now all control elements and menues are so small that I can not reed them. How can I make them readable without reducing the resolution of the schreen?

Maybe you are looking for