By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

NumberFormatException

oll3i
100+
P: 679
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
Share this Question
Share on Google+
34 Replies


Rabbit
Expert Mod 10K+
P: 12,421
Take the quotes off on line 3. You're trying to parse the variable f, not the string "f".
Sep 10 '13 #2

oll3i
100+
P: 679
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
Expert Mod 10K+
P: 12,421
Either the name of the variable you're trying to get is wrong or it's not being passed.
Sep 10 '13 #4

oll3i
100+
P: 679
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
Expert Mod 10K+
P: 12,421
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
100+
P: 679
if k is "-", it means minus 15 records
if k is "+", it means plus 15 records
Sep 11 '13 #7

oll3i
100+
P: 679
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
Expert 2.5K+
P: 3,112
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
100+
P: 679
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
Expert 2.5K+
P: 3,112
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
100+
P: 679
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
Expert Mod 10K+
P: 12,421
What does the HTML on the client side look like?
Sep 11 '13 #13

oll3i
100+
P: 679
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
Expert Mod 10K+
P: 12,421
That's the server side. I'm looking for the client side.
Sep 11 '13 #15

oll3i
100+
P: 679
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

Expert 100+
P: 785
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
100+
P: 679
with out.println("<a href=\"inbox.jsp?k=+&f=f\">");
i get
java.lang.IllegalStateException: isHexDigit
Sep 12 '13 #18

oll3i
100+
P: 679
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
100+
P: 679
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3.         CCC ccc = new CCC();
  4.         ccc.doGet(request, response);
  5.  
  6.         %> 
Sep 12 '13 #20

oll3i
100+
P: 679
if i change k=+ to k=1 it works
Sep 12 '13 #21

oll3i
100+
P: 679
how do i quote in out.println the plus sign?
out.println("<a href=\"inbox.jsp?k=+&f="+f+"\">");
Sep 12 '13 #22

oll3i
100+
P: 679
i have in url http://localhost:8080/CCC/inbox.jsp?k=+&f=0

and doGet is not working
Sep 12 '13 #23

oll3i
100+
P: 679
String k=request.getParameter("k"); is not working neither
Sep 12 '13 #24

Expert 100+
P: 785
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
100+
P: 679
out.println("<a href=\"inbox.jsp?k=%2B&f="+f+"\">");

i get java.lang.IllegalStateException: isHexDigit
Sep 12 '13 #26

Expert 100+
P: 785
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
100+
P: 679
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

Expert 100+
P: 785
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
100+
P: 679
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

Expert 100+
P: 785
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
100+
P: 679
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
100+
P: 679
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
100+
P: 679
how do i compare %2B

??
Expand|Select|Wrap|Line Numbers
  1. if(k.contentEquals("%2B")){
???
Sep 13 '13 #34

oll3i
100+
P: 679
k.equals("+"); works
Sep 13 '13 #35

Post your reply

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