Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 12th, 2011, 01:50 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default combobox unicode problem

hi,
I am a beginner in Java, JSP, and Ajax and I'm trying to create a simple form with a combobox which reads names of minerals from a database and then prints their ID.
My problem is, if I get name of mineral with special letters (š,ž,č), it get me error. My database is Unicode (UTF-8). I think there is problem with AJAX, bud i dont know where.
Can anybody help me with this?

table:
Code:
NERASTID            NERASTNAZOV
----------------------------------------
      2                       ankerit
      3                       magnetit
      4                       markazit
      9                       nežiaruvzdorné íly
     110                      železné rudy
.
.
.
.etc..
combo.jsp:
Code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>podpora</title>

<script type="text/javascript">

	function showEmp(nerast_value)
		{ 
		if(document.getElementById("nerastid").value!="-1")
		{
 			xmlHttp=GetXmlHttpObject();
			
			var url="getuser.jsp";
			url=url+"?nerastnazov="+nerast_value;
			
			

			xmlHttp.onreadystatechange=stateChanged;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);

		}
		else
		{
			 alert("Please Select mineral Id");
		}
			
	}

	function stateChanged() 
		{ 
		
		document.getElementById("nerastid").value ="";
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 			{ 
	
 			 var showdata = xmlHttp.responseText; 
   			 var strar = showdata.split(":");
	
			 if(strar.length==1)
	 		{
		  		document.getElementById("nerastid").focus();
		  		alert("Please Select mineral Id");
		  		document.getElementById("nerastnazov").value =" ";
		  		document.getElementById("nerastid").value =" ";

	 		}
	 		else if(strar.length>1)
	 			{
				var strname = strar[1];
				document.getElementById("nerastid").value= strar[1];
				
				 }
	
 			} 
		}

	function GetXmlHttpObject() 
	{
		var xmlHttp=null;
		try
 			{
 			// Firefox, Opera 8.0+, Safari
 			xmlHttp=new XMLHttpRequest();
 			}
		catch (e)
 			{
 			//Internet Explorer
 			try
  			{
  				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  			}
	   catch (e)
  		{
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
	}

	
</script>

</head>
<body>

<form name="nerasty"><br>
<br>
<table border="0" width="400px" align="center" bgcolor="#ffffff">
	<div id="mydiv"></div>
	<tr>
		<td><b>Druh nerastu</b></td>
		<td><select name="nerasty" onchange="showEmp(this.value);">			
			<option value="-1">----------Select-----------</option>
			<%
				
			
				Connection conn = null;

				int sumcount = 0;
				Statement st;
				try {
					Class.forName("oracle.jdbc.driver.OracleDriver");
					conn = DriverManager.getConnection(
							"jdbc:oracle:thin:@w08:1521:ORCL", "user","pass");
					String query = "select * from V_TBL_NERASTY";

					st = conn.createStatement();
					ResultSet rs = st.executeQuery(query);
			%>

			<%
				while (rs.next()) {
			%>

			 <option value="<%=rs.getString(2)%>"><%=rs.getString(2)%></option> 

			<%
				}
			%>

			<%
				} catch (Exception e) {
					e.printStackTrace();
				}
			%>
		</select></td>
	
	</tr>
		<td><b>Kod:</b></td>
		<td> <input type="text" id="nerastid" name="nerastid" value=""></td>
	</tr>
	
</table>
</form>
<table border="0" width="100%" align="center">
	<br>
	<br>
</table>
</body>
</html>
getuser.jsp

Code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%
	
	
	String nerastnazov = request.getParameter("nerastnazov").toString();
	
	
	String data = "";

	Connection conn = null;

	int sumcount = 0;
	Statement st;
	try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		conn = DriverManager.getConnection(
				"jdbc:oracle:thin:@w08:1521:ORCL", "user","pass");
		String query = "select * from V_TBL_NERASTY where nerastnazov = '"+nerastnazov+"'";
		
		
		st = conn.createStatement();
		ResultSet rs = st.executeQuery(query);
		
		
		while (rs.next()) {
			data = ":" + " " + rs.getString(1) + ":";
			
		}

		out.println(data);
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
  #2 (permalink)  
Old January 18th, 2011, 12:05 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok. i figured it out. There was problem with sending String..

combo.jsp
Code:
...
function showEmp(nerast_value)
      {
      if(document.getElementById("nerastid").value!="-1")
      {
          xmlHttp=GetXmlHttpObject();
         
         var url="getuser.jsp";
         url=url+"?nerastid="+nerast_value;
         
         

         xmlHttp.onreadystatechange=stateChanged;
         xmlHttp.open("GET",url,true);
         xmlHttp.send(null);
...
<option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option> 
...
getuser.jsp

Code:
...
String nerastid = request.getParameter("nerastid").toString(); 
...
String query = "select * from V_TBL_NERASTY where nerastid = '"+nerastid+"'";


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in saving unicode using ajax kumiko Ajax 1 July 23rd, 2008 02:31 AM
Asp datetime problem with non-Unicode languages neon20 Classic ASP Professional 4 March 8th, 2007 04:03 AM
Asp datetime problem with non-Unicode languages neon20 Classic ASP Databases 0 March 6th, 2007 07:49 AM
problem in unicode chandanbhakuni Classic ASP Databases 1 September 22nd, 2006 10:22 AM
Unicode ASP FIle Problem tks_muthu Classic ASP Databases 2 February 25th, 2005 06:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.