aspose file tools*
The moose likes JSP and the fly likes Integer.parseInt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Integer.parseInt" Watch "Integer.parseInt" New topic
Author

Integer.parseInt

rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41

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

Joined: Dec 11, 2004
Posts: 13410

You didn't close the first JSP tag


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: May 30, 2002
Posts: 1400
Also, put following line --> "Integer.parseInt(s1);"
inside a try-catch block.


- Varun
rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41

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

Joined: Dec 22, 2004
Posts: 15
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 ]

Maybach
Nitin Jawarkar
Ranch Hand

Joined: Dec 18, 2004
Posts: 79
hello rushikesh,

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

Thanx.


Cheers<br />Nitin
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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.


42
rushikesh kale
Ranch Hand

Joined: Jan 25, 2005
Posts: 41

Thanks For the Help !
Sorry For making new thread for that Ben
 
wood burning stoves
 
subject: Integer.parseInt
 
Similar Threads
Can resolve symbol request
To find the Medium
why not session.setAttribute working ?
Numeric Range Overlapping Strategy needed.
hello