actually i have to create dynamic number of drop down lists(depending upon number of books in that category) on jsp page pe v r creating these dynamic number of drop down lists having name rating1 ,rating2......number of buks in that category(and each drop down list has value from 0-4) n on nxt page v r accessing value using request.getparameter but on next page ven i try to print value of rating1.rating2..... it is coming null pls suggest any soln thanks in advance:) n i m also pasting both of my jsp files one setting values of drop down lists and other one accessing it in this jsp i m accessing values of rating1,rating2.... which are names given to drop down lists i hav make the line bold in which i m setting the values
<%--
Document : book_title
Created on : Aug 20, 2012, 6:24:04 AM
Author : Pradeep
--%>
<%@page import= "java.sql.*"%>
<%
int count=0,count1=0,i=1,m;
String isbn,s_no;
String op;
String subject = (String) session.getAttribute("subject");
String userid = (String) session.getAttribute("userid");
String updateString1;
String category=request.getParameter("count1");
session.setAttribute("category", category);
//String buffer="<br/><b>BOOK_TITLE</b><select name='book_title'><option value='-1'>Select</option>";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/recommender","root","purnima");
ResultSet rs2,rs3;
PreparedStatement pstmt = null;
int updateQuery=0;
Statement stmt = con.createStatement();
//Statement stmt1 = con.createStatement();
Statement stmt2 = con.createStatement();
//Statement stmt3 = con.createStatement();
System.out.println("Select book_title from book_info where subject='"+subject+"' AND CATEGORY='"+category+"'");
rs2 = stmt.executeQuery("Select S_NO,ISBN,book_title from book_info where subject='"+subject+"' AND CATEGORY='"+category+"'");
%>
<br/><b>
<% out.print(" BOOKS TO BE RATED ARE:: \n"); %>
</b><br/><br/>
<table>
<tr><td>
<% while(rs2.next())
{
count1++;
}
//session.setAttribute("count1", count1);
rs3 = stmt2.executeQuery("Select S_NO,ISBN,book_title from book_info where subject='"+subject+"' AND CATEGORY='"+category+"'");
while(rs3.next()){
// buffer=buffer+"<option value='"+rs.getString("BOOK_TITLE")+"'>"+rs.getString("BOOK_TITLE")+"</option>";
// s_no=rs3.getString("S_NO");
// isbn=rs3.getString("ISBN");
out.print(" "+rs3.getString("BOOK_TITLE")+" ");
**op ="rating"+i; %>
<select name=op>**
<% System.out.println("op is "+op); i++;
%>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option></select>
</td></tr><br/></table>
<% } %>
<center>
<form name="" ACTION="recommendation.jsp" METHOD=POST>
<input type="submit" value="SUBMIT">
</form>
</center>
<%
//buffer=buffer+"</select>";
//response.getWriter().println(buffer);
}
catch(Exception e){
System.out.println(e);
}
%>
in this fragment of jsp page i m accessing values of rating1,rating2.... which are names given to drop down lists i have made the line bold in which i am accessing the values
else
{
for(i=0;i<count1;i++)
{
**app=i+1;
name=opname+app;
val=request.getParameter(name);**
if(!val.equals("0"))
{
for(j=0;j<count2;j++)
{
if(book_isbn[i].equals(isbn[j]))//if user has changed the rating
{
flag=1;
//st.executeUpdate("UPDATE TABLE USER_LIKING SET RATING = val WHERE USERID=userid and ISBN=isbn[j]");
break;
}
}
if(flag==0)//is user had never given rating for this particular book
{
String query = "INSERT INTO USER_LIKING(USER_ID,ISBN,RATING) VALUES(?,?,?)";
pstmt = con.prepareStatement(query);
pstmt.setString(1, userid);
pstmt.setString(2, book_isbn[i][0]);
pstmt.setString(3, val);
updateQuery = pstmt.executeUpdate();
if(updateQuery!=0)
System.out.println("The record has been successfully added to our database");
}
}
}
}
}
catch(Exception e){
System.out.println(e);
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
print("code sample");