I have a JSP page where i placed some code JavaScript and SQL request. I need to convert a JavaScript variable into a Java variable, so i can call it in a SQL request. But when is search in the web, i find that Java script plays on browser where java code is server side thing. But is there any solution to do that?
<%@page import="java.util.List"%>
<%@page import="org.hibernate.Query"%>
<%@page import="util.HibernateUtil"%>
<%@page import="org.hibernate.Session"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%String variable=""; %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript"
src="http://ift.tt/eWejAD" /></script>
<script type="text/javascript">
$(document).ready(function() {
$('#champ1').hide(); // on cache le champ par défaut
$('select[name="sites"]').change(function() { // lorsqu'on change de valeur dans la liste
var valeur = $(this).val(); // valeur sélectionnée
if (valeur != '') { // si non vide
if (valeur == 'Casablanca') { // si "jaune"
$('#champ1').show();
} else {
$('#champ1').hide();
}
}
});
});
</script>
</head>
<%
Session session4 = HibernateUtil.getSessionFactory()
.getCurrentSession();
session4.beginTransaction();
Query qry = session4
.createQuery("select projet.libelle from Projet projet where projet.site='"+valeur+"'");
List list = qry.list();
%>
<body>
<form method="post" action="">
<p>
<select name="sites">
<option value="">-- Choisir --</option>
<option value="Khouribga">Khouribga</option>
<option value="Casablanca">Casablanca</option>
</select><br />
</p>
</form>
<table border="1" cellpadding="3pt" align="center">
<tr>
<td>Nom du projet :</td>
</tr>
<%
for (int i = 0; i < list.size(); i++) {
%>
<tr>
<td><%=list.get(i).toString()%></td>
</tr>
<
<%
}
%>
</body>
Aucun commentaire:
Enregistrer un commentaire