• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in request.getParameter

 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

I am devwloping a simple JSP page which will convert INR to Dollar but I get following Error:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /TestConver.jsp at line 13

10: <body>
11: <%
12: String str=request.getParameter("input");
13: int x=Integer.parseInt("str");
14: double d=(double)50/x;
15: %>
16:

Please find my both JSP and HTML page code as below:

HTML Page:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Conversion Table</title>
</head>
<form name ="test" method="post" action="TestConver.jsp">
<body>
<select name="sel">
<option> INR to Dollar </option>
<option> Meter to KiloMeter </option>
<option> INR to Dollar </option>
</select>

<Input type="text" value=" " name="input"> Enter the Data:</Input>

<Input type="submit" value="Enter" name="submit" > Enter</Input>


</body>
</html>

JSP Page:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import=" java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Conversion here</title>
</head>
<body>
<%
String str=request.getParameter("input");
int x=Integer.parseInt("str");
double d=(double)50/x;
%>

<%=request.getParameter("sel")%>


<%=d %>
</body>
</html>

Guide me what to do
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is in below line



You are passing "str" and asking to convert into integer. You should pass the value of str as below and make sure the value you give to "str" is numerical value.



Also make sure that you post all your code within the code tags. This would help readers to understand your code easily.
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After chagne in code I am getting same error.
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's working now thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic