473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

NumberFormatException

oll3i
679 512MB
Hi,

I get org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "f"
root cause
in the below code

Expand|Select|Wrap|Line Numbers
  1.  
  2. String f= request.getParameter("f");
  3. int from = Integer.parseInt("f");
  4.  
  5.  

Thank You
Sep 10 '13 #1
34 5150
Rabbit
12,516 Expert Mod 8TB
Take the quotes off on line 3. You're trying to parse the variable f, not the string "f".
Sep 10 '13 #2
oll3i
679 512MB
still the same error

org.apache.jasper.JasperException: java.lang.NumberFormatException: null

seems like f is null
so why it does not read request.getParameter("f") in doGet
Sep 10 '13 #3
Rabbit
12,516 Expert Mod 8TB
Either the name of the variable you're trying to get is wrong or it's not being passed.
Sep 10 '13 #4
oll3i
679 512MB
i have it in a link
Expand|Select|Wrap|Line Numbers
  1. out.println("<a href=\"inbox.jsp?k=-&f="+f+">")
it reads k but not f
Sep 10 '13 #5
Rabbit
12,516 Expert Mod 8TB
What is k? Why is it just a dash?

You may want to also check the value of f on the client side.
Sep 10 '13 #6
oll3i
679 512MB
if k is "-", it means minus 15 records
if k is "+", it means plus 15 records
Sep 11 '13 #7
oll3i
679 512MB
In doGet i have an error. k=null and f=null.

Why it does not take these variables from url?
Sep 11 '13 #8
Nepomuk
3,112 Expert 2GB
Just a thought: Shouldn't that code be in the doPost method rather than doGet? Maybe that would explain the null values.
Sep 11 '13 #9
oll3i
679 512MB
doPost works when i send the data from a form but when i want to read data from url it does not work
Sep 11 '13 #10
Nepomuk
3,112 Expert 2GB
OK, next idea:
Expand|Select|Wrap|Line Numbers
  1. out.println("<a href=\"inbox.jsp?k=-&f="+f+">")
This might be missing the end of the href quote:
Expand|Select|Wrap|Line Numbers
  1. out.println("<a href=\"inbox.jsp?k=-&f="+f+"\">")
Just to make sure, I'd check how the link is rendered in the resulting HTML.
Sep 11 '13 #11
oll3i
679 512MB
http://localhost:8080/CCC/c.jsp?k=+&f=0
not working :(
Expand|Select|Wrap|Line Numbers
  1. public void doGet(HttpServletRequest request, HttpServletResponse response)  
  2.             throws ServletException, IOException {  
  3.          String k=request.getParameter("k");
  4.  
  5.       String f= request.getParameter("f");
  6.  
  7.  
  8.       int from = Integer.parseInt(f);
  9.  
still k and f = null
Sep 11 '13 #12
Rabbit
12,516 Expert Mod 8TB
What does the HTML on the client side look like?
Sep 11 '13 #13
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. response.setContentType("text/html");   
  2.         PrintWriter out = response.getWriter(); 
  3.         out.println("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"css.css\"/><title>HRMailer</title></head><body>");
  4.         out.println("<table width=\"900\">");
  5.         out.println("<tr><td>");
  6.                      if(f>=15) { 
  7.         out.println("<a href=\"inbox.jsp?k=-&f="+f+"\">");
  8.  
  9.                        out.println("<< prev");  
  10.  
  11.                     out.println("</a>");
  12.                      } 
  13.                     out.println("<a href=\"inbox.jsp?k=+&f="+f+"\">");                    out.println("next >>");    
  14.                     out.println("</a>");
  15.  
  16.                 out.println("</td></tr></table");      
  17.  
  18.        out.println("<table width=\"150\">");
  19.             out.println("<tr>");
  20.                 out.println("<td valign=\"top\"> ");    
  21.             out.println("<table align=\"left\">");
  22.                 out.println("<tr><td width=\"150px\" aling=\"left\">");
  23.                 out.println("<a href=\"inbox.jsp\">Inbox</a></td></tr>");
  24.                 out.println("<tr><td><a href=\"sent.jsp\">sent</a></td></tr>");
  25.                 out.println("<tr><td><a href=\"drafts.jsp\">drafts</a></td></tr>"); 
  26.                 out.println("<tr><td><a href=\"trash.jsp\">Trash</a></td></tr>"); 
  27.             out.println("</table>");
  28.  
  29.  
  30.         out.println("<table cols=\"5\" alin=\"left\"><form action=\"do.jsp\" method=\"post\">");
  31.             out.println("<tr class=\"span1rstRow\">");
  32.             out.println("<td>");
  33.                out.println("c");          
  34.                out.println("</td>");    
  35.             out.println("<td>d?</td>");
  36.                 out.println("<td>");
  37.                   out.println("Subject:"); 
  38.                 out.println("</td>");
  39.                 out.println("<td>");
  40.                   out.println("From:");  
  41.                 out.println("</td>");
  42.                 out.println("<td>");
  43.                   out.println("Date:"); 
  44.                 out.println("</td>");
  45.             out.println("</tr");
  46.            HttpSession session = request.getSession();
  47.  
  48.           Connect connectToImap = new Connect(); 
  49.           connectToImap.login((String)session.getAttribute("username"),(String)session.getAttribute("password"));
  50.  
  51.  
  52.         Message[] messages = connectToImap.fetchMails();
  53.        System.out.println("connect.fetchMails();");
  54.        System.out.println(request.getParameter("k"));
  55.  
  56.  
  57.        try{
  58.         for (int i=f; i < t ;i++){ 
  59.  
  60.             Message msg =  messages[i]; 
  61.         if (msg.isSet(Flags.Flag.DELETED)) 
  62.              { continue; } else {
  63.             out.println("<tr>");
  64.             out.println("<td>");
  65.             out.println("<input type=\"checkbox\" name=\"do\" value="+i+">");          
  66.             out.println("</td>");
  67.             out.println("<td>");
  68.             out.println("d");          
  69.             out.println("</td>"); 
  70.             out.println("<a href=open.jsp?i="+i+">");
  71.  
  72.            String subject = msg.getSubject();
  73.  
  74.             out.println("<td>");
  75.             out.println(subject);
  76.             out.println("</td>");
  77.             out.println("<td>");
  78.             out.println(InternetAddress.toString(messages[i].getFrom()));
  79.             out.println("</td>");
  80.  
  81.  
  82.             out.println("<td>");
  83.  
  84.             out.println(messages[i].getReceivedDate());
  85.             out.println("</td");        
  86.              out.println("</tr> ");
  87.             out.println("</a>");
  88.           } }  
  89.         out.println("</table></form>");
  90.                 out.println("</td>");
  91.            out.println(" </tr>");
  92.         out.println("</table>");
  93.         out.println("<body></html>");
  94.     out.close();
  95.     } catch (MessagingException e){
  96. e.printStackTrace();
  97.     }
  98.    }
  99.  
Sep 11 '13 #14
Rabbit
12,516 Expert Mod 8TB
That's the server side. I'm looking for the client side.
Sep 11 '13 #15
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. <html><head><link rel="stylesheet" type="text/css" href="css.css"/><title>HRMailer</title></head><body>
  2. <table width="900">
  3. <tr><td>
  4. <a href="inbox.jsp?k=+&f=0">
  5. next >>
  6. </a>
  7.  
Sep 12 '13 #16
chaarmann
785 Expert 512MB
Maybe I'm wrong, but using "+" as a value for variable k can be the reason that k and f have no values.
How?
You are using "+" directly in your URL when creating it with out.println. ( For example you print out href="inbox.jsp?k=+&f=12") But you should use the hex-code string "%2B" for it instead "+". Because a plus-sign is converted to space when submitted to the server. When there is some redirection or other double-parsing of the URL, the space determines the end of the URL, therefore all characters following this space are cut off. (In your case "inbox.jsp?k= &f=12" changes to "inbox.jsp?k="). The effect is that both variable k and f are empty.
Sep 12 '13 #17
oll3i
679 512MB
with out.println("<a href=\"inbox.jsp?k=+&f=f\">");
i get
java.lang.IllegalStateException: isHexDigit
Sep 12 '13 #18
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. <html><head><link rel="stylesheet" type="text/css" href="css.css"/><title>HRMailer</title></head><body>
  2. <table width="900">
  3. <tr><td>
  4. <a href="inbox.jsp?k=+&f=0">
  5. next >>
  6. </a>
  7.  
http://localhost:8080/CCCC/cccc.jsp?k=+&f=0

org.apache.jasper.JasperException: java.lang.NumberFormatException: null
Sep 12 '13 #19
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3.         CCC ccc = new CCC();
  4.         ccc.doGet(request, response);
  5.  
  6.         %> 
Sep 12 '13 #20
oll3i
679 512MB
if i change k=+ to k=1 it works
Sep 12 '13 #21
oll3i
679 512MB
how do i quote in out.println the plus sign?
out.println("<a href=\"inbox.jsp?k=+&f="+f+"\">");
Sep 12 '13 #22
oll3i
679 512MB
i have in url http://localhost:8080/CCC/inbox.jsp?k=+&f=0

and doGet is not working
Sep 12 '13 #23
oll3i
679 512MB
String k=request.getParameter("k"); is not working neither
Sep 12 '13 #24
chaarmann
785 Expert 512MB
how do i quote in out.println the plus sign?
Did you have difficulties understanding my previous reply? (if yes, don't hesitate to ask)
I told you to use the hex value "%2B" for it. That means:
Expand|Select|Wrap|Line Numbers
  1. out.println("<a href=\"inbox.jsp?k=%2B&f="+f+"\">");
if i change k=+ to k=1 it works
That means I was right and the improper coding of the plus-sign caused it the way I described.
You should also be careful in coding other characters. Like space should be coded as "+" or as "%20".

Plase try it again and tell me if it works now.
Sep 12 '13 #25
oll3i
679 512MB
out.println("<a href=\"inbox.jsp?k=%2B&f="+f+"\">");

i get java.lang.IllegalStateException: isHexDigit
Sep 12 '13 #26
chaarmann
785 Expert 512MB
Are you using Glassfish4 ? Then most likely it is a bug, try to download the patch for glassfish.

Or:
Try using "%31" (which is digit "1") instead of "%2B". I just want to know if hex-digit parsing is a common problem for your Server.

Another try: use single quotation marks instead of double quotation marks. That means, use:
Expand|Select|Wrap|Line Numbers
  1. out.println("<a href='inbox.jsp?k=%2B&f="+f+"'>");
Sep 12 '13 #27
oll3i
679 512MB
I get blank page with
Expand|Select|Wrap|Line Numbers
  1.  out.println("<a href='inbox.jsp?k=%2B&f="+f+"'>");
I use GlassFish 4
Sep 13 '13 #28
chaarmann
785 Expert 512MB
And what about the other 2 possibilities?

Did you apply the glassfish-patch?
Did using "%31" work?

Another thing that would help greatly:
You are generating HTML that is send to the client browser. So just right-click in the browser page and select "view source" in the popup-menu. Locate the generated code that contains the "<a href..." from above and paste it here in this forum thread for further analysis.

Then we can decide if getting a blank page is one step to the solution and we solved the first error (hex-parsing). There may be a second error following the first one, like the link works, but the following page "inbox.jsp" contains an error somewhere, resulting in a blank page returned.
Sep 13 '13 #29
oll3i
679 512MB
when i use %31 i get blank page using
Expand|Select|Wrap|Line Numbers
  1. out.println("<a href='inbox.jsp?k=%2B&f="+f+"'>"); 
also generates a blank page
Sep 13 '13 #30
chaarmann
785 Expert 512MB
Did you apply the glassfish-patch?

Can you please quote the HTML here?

What about the blank page, can you quote its HTML here, too?

When you get the blank page, then was it going to inbox.jsp before, or it went somewehre else? That means, if you insert a System.out.print statement inside inbox.jsp right at the beginning, was something printed?
Sep 13 '13 #31
oll3i
679 512MB
with
Expand|Select|Wrap|Line Numbers
  1. String k=request.getParameter("k");System.out.println("k="+k);
i get in output k=+
Sep 13 '13 #32
oll3i
679 512MB
with
Expand|Select|Wrap|Line Numbers
  1. String k=request.getParameter("k");
  2.         String f=request.getParameter("f");
  3.  
  4.         System.out.println("k="+k);
  5.         System.out.println("f="+f); 
i get k=+ and f=0 what is correct
now i have to work on doGet :)

Thank You
Sep 13 '13 #33
oll3i
679 512MB
how do i compare %2B

??
Expand|Select|Wrap|Line Numbers
  1. if(k.contentEquals("%2B")){
???
Sep 13 '13 #34
oll3i
679 512MB
k.equals("+"); works
Sep 13 '13 #35

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Joe | last post by:
Hi, I am trying to connect to a MySQL database through a Java Servlet. I think I have correctly installed Tomcat 4.1.30 and the MySQL Database along with ConnectorJ. I am getting a...
3
by: satyakarvvk | last post by:
Hi everybody! Please help me to overcome below runtime exception. Actually it is a simple program on basics. I want to print odd nos upto which the user asks and after printing the task,...
4
by: soty | last post by:
HI i wrote a code to validate cash for a vending machine.... the problem am having is dat dat my code failed to validate any ammount. please help!!!! the code is below
3
by: smileyme74 | last post by:
Every time I enter for example 1 mile, I get the error. /** * This program will convert measurements expressed in inches, * feet, yards, or miles into each of the possible units of *...
1
by: prasanna ganesh | last post by:
why i'm getting lang.string.NumberFormatException for input string ""please help me to find solution
7
by: om anand giri | last post by:
Hello to all, I have a problem about NumberFormatException and i m very sad because i m not able to solve this. So please help. The code is---------- <code> <%@page...
1
by: AnandhaMurugan | last post by:
I got a numberformatException when i convert from string to decimal how to resolve it java.lang.NumberFormatException at java.math.BigDecimal.<init>(BigDecimal.java:455) at...
1
by: Ronak U | last post by:
import java.io.*; class ShellSort { static void shSort(int a) { int i,k,x,width; width=a.length/2; while(width>=1) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.