[更新]ボタンをクリックすると、jsp(更新用)のポップアップが開きます。また私はmain.jsp
からupdate.jsp
に良いid(Urunler id)を送っています。しかし、いつもポップアップJSPにはIDが後ろから来ています。たとえば、私はmain.jsp
の1.idをクリックし、?id=1
としてokを返しますが、ポップアップJSPはnull(formatExceptionを送信)です。もう一度クリックすると、2. idをクリックすると、ポップアップJSPが?id=1
と表示されます。だから、イドはいつも背中から来る。 main.jspでポップアップjsp java.lang.NumberFormatException:null
マイクリックコード:main.jspで
<td>
<a onclick='popup()' href="managergosterim.jsp?id=<%=user.getUrunId()%>" >Güncelle</a>
</td>
ポップアップJSPものは:
function popup(){
window.open('update.jsp?<%=request.getQueryString()%>','name','width=500,height=500');
}
これが私のmain.jspある
<%@page import="entities.Urunler"%>
<%@page import="org.hibernate.Query"%>
<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="entities.Uyeler"%>
<%@page import="org.hibernate.cfg.AnnotationConfiguration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MANAGER Ürünler</title>
</head>
<body>
<divdisplay:block;>
<div id="index">
<img style="float: right; display:inline-block; " src="Manager.png" alt="Manager" />
</div>
<div id="sidebar">
<form class="login" action="logout.jsp" method="Post">
<input type="submit" style="float:right; display:inline-block; margin: 5px; margin-bottom: 0px; " class="submit" value=" Çıkış Yap " />
</form> <br><br>
<form class="login" action="Raporlama" method="Post">
<input type="submit" style="float:right; margin: 5px; margin-bottom: 0px; display:inline-block; " class="submit" value=" PDF Oluştur " />
</form> <br><br>
</div>
</div>
<table border=1 style="float:top" ><tr><th>Marka</th><th>Model</th><th>Fiyat</th><th>Renk</th><th colspan="3">Seçenekler</th> </tr>
<%
//**HERE WE RETRIEVE MANAGER DATABASE TABLES.**
out.println("<title>MANAGER Ürünler</title>");
HttpSession oturum = request.getSession();
AnnotationConfiguration configiki = new AnnotationConfiguration();
configiki.addAnnotatedClass(Uyeler.class);
SessionFactory factory = configiki.configure().buildSessionFactory();
Session sessioniki = factory.getCurrentSession();
sessioniki.beginTransaction();
Query queryResult = sessioniki.createQuery("from Urunler");
java.util.List allUsers;
allUsers = queryResult.list();
for (int i = 0; i < allUsers.size(); i++) {
Urunler user = (Urunler) allUsers.get(i);
%>
<tr>
<td><%=user.getMarka()%></td>
<td> <%=user.getModel()%></td>
<td><%=user.getPrice()%></td>
<td><%=user.getRenk()%></td>
<td> <a onclick='popup()' href="managergosterim.jsp?id=<%=user.getUrunId()%>" >Güncelle</a> </td>
<td> <a href="del.jsp?id=<%=user.getUrunId()%>">Sil</a> </td>
</tr>
<%
}
//**EACH TABLE ROWS HAVE DELETE(href to DEL.Jsp) AND UPDATE(HREF TO GUNCELLE.JSP) .**
%>
</table>
<script>
function popup(){
window.open('update.jsp?<%=request.getQueryString()%>','name','width=500,height=500');
}
</script>
</body>
</html>
これはポップアップJSPです。
<%@page import="org.hibernate.Query"%>
<%@page import="java.util.List"%>
<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="entities.Urunler"%>
<%@page import="org.hibernate.cfg.Configuration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
.mdl {
font-size: 20px;
font-family: serif;
margin: 5px;
}
</style>
</head>
<body>
<h3>Ürünün yeni değerlerini giriniz</h3>
<form>
<%!void degistir() {
HttpServletRequest request = null;
String marka = request.getParameter("marka");
String model = request.getParameter("model");
String fiyat = request.getParameter("fiyat");
String renk = request.getParameter("renk");
Configuration confi = new Configuration();
confi.addAnnotatedClass(Urunler.class);
SessionFactory factor = confi.configure().buildSessionFactory();
Session oturumiki = factor.getCurrentSession();
oturumiki.beginTransaction();
List allItem;
Query queryResultz = oturumiki.createQuery("from Urunler");
allItem = queryResultz.list();
for (int i = 0; i < allItem.size(); i++) {
Urunler urun = (Urunler) allItem.get(i);
if (request.getParameter("id").equals(urun.getUrunId())) {
urun.setMarka(marka);
urun.setModel(model);
urun.setPrice(Integer.parseInt(fiyat));
urun.setRenk(renk);
}
}
}%> <%
int gelenid = Integer.valueOf(request.getParameter("id"));
out.println("gelen id su : " + gelenid);
Configuration configiki = new Configuration();
configiki.addAnnotatedClass(Urunler.class);
SessionFactory factory = configiki.configure().buildSessionFactory();
Session sessioniki = factory.getCurrentSession();
sessioniki.beginTransaction();
List allItems;
Query queryResult = sessioniki.createQuery("from Urunler");
allItems = queryResult.list();
for (int i = 0; i < allItems.size(); i++) {
Urunler urun = (Urunler) allItems.get(i);
if (gelenid == urun.getUrunId()) {
%>
Marka : <input type="label" class="mdl" name="marka"
value="<%=urun.getMarka()%>" /><br> Model : <input type="label"
class="mdl" name="model" value="<%=urun.getModel()%>" /><br>
Fiyat : <input class="mdl" type="label" name="fiyat"
value="<%=urun.getPrice()%>" /><br> Renk : <input
type="label" class="mdl" name="renk" value="<%=urun.getRenk()%>" /> <br>
<br> <input
type="submit" class=mdl value="Değiştir" onClick="degistir()" />
<%
}
}
%>
</form>
</body>
</html>
のTyを変更 –