I am getting the inputs "distance" and "service " from a previous html page and passing the values here to calculate "estimateamt" and pass the calculated "estimateamt" to a jsp page "service2.jsp" using session attribute
package packk;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class query2 extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String s=request.getParameter("distance");
String tr=request.getParameter("service");
try{
long d=Long.parseLong(s);
HttpSession sess=request.getSession();
sess.setAttribute("distance",s);
sess.setAttribute("service",tr);
String op1,op2,op3,op4,op5,op6;
op1="Intra City Relocation";
op3="Inter State Relocation";
op5="Intra State Relocation";
op2="Intra City Moving";
op4="Inter State Moving";
op6="Intra State Moving";
long ea=0;
sess.setAttribute("estimateamt",ea);
if(d<=250)
{
if(tr.equals(op1))
{
ea=d*10;
}
else if(tr.equals(op2))
{
ea=d*5;
}
else if(tr.equals(op3))
{
ea=d*20;
}
else if(tr.equals(op4))
{
ea=d*10;
}
else if(tr.equals(op5))
{
ea=d*20;
}
else if(tr.equals(op5))
{
ea=d*15;
}
}
else if(d<=500)
{
if(tr.equals(op1))
{
ea=d*10;
}
else if(tr.equals(op2))
{
ea=d*5;
}
else if(tr.equals(op3))
{
ea=d*20;
}
else if(tr.equals(op4))
{
ea=d*10;
}
else if(tr.equals(op5))
{
ea=d*20;
}
else if(tr.equals(op5))
{
ea=d*15;
}
}
else if(d<=1000)
{
if(tr.equals(op1))
{
ea=d*10;
}
else if(tr.equals(op2))
{
ea=d*5;
}
else if(tr.equals(op3))
{
ea=d*20;
}
else if(tr.equals(op4))
{
ea=d*10;
}
else if(tr.equals(op5))
{
ea=d*20;
}
else if(tr.equals(op5))
{
ea=d*15;
}
}
else if(d>1000)
{
if(tr.equals(op1))
{
ea=d*10;
}
else if(tr.equals(op2))
{
ea=d*5;
}
else if(tr.equals(op3))
{
ea=d*20;
}
else if(tr.equals(op4))
{
ea=d*10;
}
else if(tr.equals(op5))
{
ea=d*20;
}
else if(tr.equals(op5))
{
ea=d*15;
}
}
}
catch(Exception e)
{
}
response.sendRedirect("service2.jsp");
}
}
@@@@@@@@@@@@ this is the end of the servlet .Now the service.jsp is given below
<%
HttpSession sess=request.getSession();
String dist=(String)sess.getAttribute("distance");
String transport=(String)sess.getAttribute("service");
String amt=(String)sess.getAttribute("estimateamt");
%>
<html>
<body background="images\wall2.jpg">
<b> Shifting distance:<%=dist%><br><br>
<b>Shifting Type:<%=transport%><br><br>
<b>Estimated Amount:<%=amt%><b><br><br>
</td>
<br>
<br>
<br><br>
<br>
</table>
</table>
</body>
</html>
Now when i run the servlet i am getting an error as follows :
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
root cause
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
I understand that the error has something to do with the estimate amount calculation and conversion of String to Long related..but i could not resolve the problem ..kindly help me where to make changes in the code or where i have done wrong..i am just a beginner...