| | |
| Stránka: 1 z 1
| [ Príspevkov: 2 ] | |
Autor | Správa |
---|
Registrovaný: 12.01.11 Prihlásený: 17.01.11 Príspevky: 2 Témy: 1 | Napísal trexi: 12.01.2011 15:13 | |
|
zdravim,
som zaciatocnik v Jave, JSP a ajaxe a snazim sa vytvorit jednoduchy formular s comboboxom, ktory nacita nazvy nerastov z databazy a na zaklade nich potom vypise ich ID. Moj problem spociva v tom, ze ak nacitam nazov bez diakritiky tak sa jeho ID zobrazi spravne. Ak je to vsak s diakritikou, vypise chybu.. Nevie mi s tym prosim niekto pomoct?
Tabulka vyzera takto:
Kód: NERASTID NERASTNAZOV ---------------------------------------- 2 ankerit 3 magnetit 4 markazit 9 nežiaruvzdorné íly 110 železné rudy . . . .atd.. combo.jsp: Kód: <%@ 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 Employee 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 Employee 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 Kód: <%@ 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(); } %>
|
|
Registrovaný: 12.01.11 Prihlásený: 17.01.11 Príspevky: 2 Témy: 1 | Napísal autor témy trexi: 18.01.2011 16:56 | |
|
OK, je to vyriesene.. chyba bola v tom ze som posielala Stringy namiesto ID..
combo.jsp
Kód: ... 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 Kód: ... String nerastid = request.getParameter("nerastid").toString(); ... String query = "select * from V_TBL_NERASTY where nerastid = '"+nerastid+"'";
|
|
| Stránka: 1 z 1
| [ Príspevkov: 2 ] | |
Podobné témy | Témy | Odpovede | Zobrazenia | Posledný príspevok |
---|
| [ C++ ] ComboBox + Edit v Assembler, C, C++, Pascal, Java | 3 | 1668 | 31.01.2010 1:18 stopa27 | | C++ Builder ComboBox v Assembler, C, C++, Pascal, Java | 2 | 625 | 17.01.2009 0:30 toma-mato | | EXCEL - cyklus na combobox v Ostatné programy | 1 | 1047 | 28.07.2009 17:10 PaloPa | | Dual combobox v HTML/PHP v HTML, XHTML, XML, CSS | 5 | 805 | 14.04.2015 17:47 void | | ComboBox a využitie z pohľadu MySQL v Delphi, Visual Basic | 11 | 832 | 30.07.2010 9:08 Manny | | JSP na localhoste v Ostatné | 1 | 299 | 04.09.2012 19:06 shaggy | | JSP Free hosting v Webhosting a servery | 1 | 1181 | 12.06.2008 13:45 Ded'leg | | JSP a duplicita kodu v Assembler, C, C++, Pascal, Java | 3 | 313 | 15.05.2010 11:03 enuwa2 | | JSP login a zobrazovanie v Assembler, C, C++, Pascal, Java | 7 | 465 | 10.02.2009 13:12 myxall | | JSP - Remember Login pomocou cookie v Assembler, C, C++, Pascal, Java | 0 | 276 | 21.01.2010 13:21 myxall | | náhrada za zdroj ATX-400 JSP v PC skrinky, zdroje a všetky druhy chladenia | 20 | 1094 | 04.01.2021 16:02 dark_globe | | dobre java navody a nova tema JAVA [ Choď na stránku: 1, 2 ] v Assembler, C, C++, Pascal, Java | 35 | 5429 | 09.03.2009 17:14 tlacitko Enter | | Rozdiel medzi Java Standard a Java EE v Assembler, C, C++, Pascal, Java | 1 | 840 | 02.04.2014 12:41 XOLOO | | ako z JSP zavolat metodu v triede v Assembler, C, C++, Pascal, Java | 6 | 486 | 16.04.2008 17:05 m@-nX | | free webhosting so 100% podporou javy a jsp v Webhosting a servery | 0 | 899 | 11.05.2010 11:37 jarrro | | Nový 48-jadrový procesor šampiónom v Jave a jsp v Novinky | 1 | 603 | 15.12.2006 8:41 ertin |
| Nemôžete zakladať nové témy v tomto fóre Nemôžete odpovedať na témy v tomto fóre Nemôžete upravovať svoje príspevky v tomto fóre Nemôžete mazať svoje príspevky v tomto fóre
|
|