Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integer.parseInt

 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys
I have problem in compiling my jsp page at following code :
<%! int i;
String s1;
<%s1=request.getParameter("t1");
i=Integer.parseInt(s1);
%>
I got Error as cannot resolve symbol 'request'. Please help me out
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't close the first JSP tag
 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry that i missed while coping But my problem still not solved after writing this code:
<%! int i;
String s1;%>
<%s1=request.getParameter("t1");
i=Integer.parseInt(s1);
%>
I got Error as cannot resolve symbol 'request'. Please help me out
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the error I'm getting. I just tried your code and got:


java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:436)
java.lang.Integer.parseInt(Integer.java:518)
org.apache.jsp.test_jsp._jspService(test_jsp.java:46)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

note

Which is the error I would have expected.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure your JSP code doesn't look like this?:


Becuase, then, the compiler wouldn't recognize the request variable.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, put following line --> "Integer.parseInt(s1);"
inside a try-catch block.
 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I consider Ben and Varun Suggestion , My errors are reduced but i still have error as :
C:\jws\tmpdir\default\pagecompile\jsp\_OrderMain.java:26: cannot resolve symbol
symbol : variable request
location: class pagecompile.jsp._OrderMain
String s1= request.getParameter("t1");


Now My code is: <%! String s1= request.getParameter("t1");%>
<%try {%>
<%! int i=Integer.parseInt(s1);%>
<% }
catch(Exception e)
{
e.printStackTrace();
}
%>
 
Maybach Smith
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP declarations do not have access to automatically defined variables like request, response etc.
Please go through this
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-JSP.html
for understanding this.
Also,check Ben has already pointed that you cannot access request in declaration.
Thanks
[ January 28, 2005: Message edited by: Maybach Smith ]
 
Nitin Jawarkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello rushikesh,

write your request.getParameter(); method in scriplet <% %>but not in expression <%! %> ok, hope it will work fine.

Thanx.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't use global blocks anyway.
You're effectively making your int a static variable which I doubt is your intention.

Follow the advice given here countless times already: JSPs are to be used only for displaying data, not for manipulating it.
 
rushikesh kale
Ranch Hand
Posts: 41
Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks For the Help !
Sorry For making new thread for that Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic