passing data between the jsp pages ?

passing data between the jsp pages ?

i developed a project on student marks system.in this project their is one html page which asks user to enter the roll number and when we press submit button on that page it moves a jsp page .on that jsp page it retrieve marks regarding the particular roll number and displays the marks and i write another jsp which will calculate the percentage of the marks. from the previous jsp page the data needs to pass.i use for that.when i use the jsp forward the contrlol directly goes to the percentage page without presenting the marks

    but i need to present the both marks as well as percentage

 PLEASE HELP ME TO SOLVE THIS PROBLEM
View Answers

June 18, 2011 at 4:58 PM

1)form6.jsp:

<html>
<form method="post" action="retrieve.jsp">
Enter RollNo:  <input type="text" name="roll"><br><br>
<input type="submit" value="Submit">
</form>
</html>

2)retrieve.jsp:

<%@page import="java.sql.*"%>
<form method="post" action="display.jsp">
<table>
<%
int roll=Integer.parseInt(request.getParameter("roll"));
Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from student where id="+roll+"");
if(rs.next()){
%>
<tr><td>Roll No: </td><td><input type="text" name="id" value="<%=rs.getInt("id")%>"></td></tr>
<tr><td>Marks: </td><td><input type="text" name="marks" value="<%=rs.getInt("marks")%>"></td></tr>
<%
}
%>
</table>
<input type="submit" value="Submit">
</form>

3)display.jsp:

<%@page import="java.sql.*"%>
<table>
<%
int id=Integer.parseInt(request.getParameter("id"));
double marks=Double.parseDouble(request.getParameter("marks"));

double tmarks=500;
double percentage=(marks/tmarks)*100;
System.out.println(id+" "+marks+" "+percentage);
%>
<tr><td>Roll No: </td><td><input type="text" name="id" value="<%=id%>"></td></tr>
<tr><td>Marks: </td><td><input type="text" name="marks" value="<%=marks%>"></td></tr>
<tr><td>Percentage:</td><td><input type="text" value="<%=percentage%>"></td></tr>
</table>









Related Tutorials/Questions & Answers:

Ads