Results 1 to 2 of 2
  1. #1
    zohaib82 is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default how to get utf-8 data from query string in JSP and add in database.


    I want to get utf-8 data from query string in jsp page therefore I have written following JSP page

    But I am getting garbage instead of utf-8 data.

    I want to know how to get utf-8 data from query string in JSP and add in databse.

    Any solution?
    Java Code:
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    <%@ page import="java.sql.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.util.Random.*"%>
    String strFirstName=request.getParameter("firstname");
    String strLastName=request.getParameter("lastname");
    String strEmail=request.getParameter("email");
    String strPassword=request.getParameter("password1");
    out.println("<br/>First Name => "+strFirstName);
    out.println("<br/>Last Name => "+strLastName);
    out.println("<br/>Email => "+strEmail);
    out.println("<br/>Password => "+strPassword);
    Connection conn;
    int rs;
    int Flag=0;
    String Query=null;
    PreparedStatement stat = null;
    conn = DriverManager.getConnection("jdbc:odbc:xe","system","mypassword"); 
    Random randomGenerator = new Random();
    int ID = randomGenerator.nextInt();
    String sql =" INSERT INTO CONTACTS (id,firstname,lastname,email,password1) VALUES (?,?,?,?,?) ";
    stat = conn.prepareStatement(sql);
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
    <html xmlns="" xml:lang="en">
    <title>New Contact</title>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
    <link href="Site.css" rel="stylesheet" type="text/css" />
    <form id="frmForm" name="frmForm" method="get" action="form.jsp">
    <table width="500" align="left" border="0">
        <td colspan="2" align="center" class="accountInfo"><div align="left"><h2>New Contact Information</h2> </div></td>
        <td colspan="2" align="center" class="accountInfo">&nbsp;</td>
        <td colspan="2" align="center" class="accountInfo">&nbsp;</td>
        <td colspan="2" align="center" class="accountInfo">&nbsp;</td>
        <td width="200" align="center"><div align="left"><strong>First Name  </strong><span class="style3">* </span></div></td>
        <td width="300" align="left"><label>
          <input type="text" width="300px" name="firstname" id="firstname" />
        <td width="200" align="center"><div align="left"><strong>Last Name</strong><span class="style3"> *</span> </div></td>
        <td width="300" align="left"><input width="300px" type="text" name="lastname"  id="lastname"/></td>
        <td width="200" align="center"><div align="left"><strong>Email</strong></div></td>
        <td width="300" align="left"><input width="300px" type="text" name="email"  id="email"/></td>
        <td width="200" align="center"><div align="left"><strong>Password</strong></div></td>
        <td width="300" align="left"><input width="300px" type="password" name="password1"  id="password1"/></td>
        <td align="left"><label>
          <input type="submit" name="Submit" value="Submit" />

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: how to get utf-8 data from query string in JSP and add in database.

    What do you see on the page when you run this?
    What should you see?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Formatting String data from database
    By computerbum in forum JDBC
    Replies: 1
    Last Post: 04-28-2010, 01:27 PM
  2. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  3. Query in database
    By anki1234 in forum JDBC
    Replies: 3
    Last Post: 08-20-2008, 05:45 PM
  4. [SOLVED] General string problem in my database query.....?
    By prabhurangan in forum New To Java
    Replies: 7
    Last Post: 06-25-2008, 08:55 AM
  5. How to query data from database using SSL
    By mano in forum New To Java
    Replies: 0
    Last Post: 08-02-2007, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts