Solved

Converting int to String

Posted on 2003-11-06
17
52,379 Views
Last Modified: 2011-08-18
How to convert an integer value to string?

// for string to integer we use
string s = "1";
int i = Integer.parseInt(s);

//what code should b used to convert an int, with the value given below, to string

int i=1;
...????

In ASP we use CStr for that purpose, what is it's alternate used here in JSP... It's urgent
0
Comment
Question by:adnan_rais
  • 6
  • 6
  • 2
  • +3
17 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 9697777
String s = new Integer(i).toString();

OR

String s = "" + i;


0
 
LVL 6

Expert Comment

by:kotan
ID: 9697890
Integer.toString(i);
0
 

Author Comment

by:adnan_rais
ID: 9698060
The source code is as follows... none of the solutions defined by kotan and bobbit31 worked properly as the program returns some error regarding to NullPointerException. Remember I'm using JBuilder 7 as the development tool n can't b changed due to the need of my assignment. So what's the correct solution......??? It's urgent

   <select name="day">
      <option value="none">Day</option>
<%
  String mday;
  for(int i=1; i<=31; i++)
   {
     mday = new Integer(i).toString();
     if(mday.equals(request.getParameter("day"))){
       out.println("<option selected>" + mday + "</option>");
     }else
     out.println("<option value=" + i + ">" + i + "</option>");
   }
%>
   </select>
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 18

Accepted Solution

by:
bobbit31 earned 20 total points
ID: 9698185
make sure request.getParameter("day") is not null!

you can do this as well:

String day = request.getParameter("day");

if(day != null && mday.equals(day)) {
       out.println("<option selected>" + mday + "</option>");
     }else
     out.println("<option value=" + i + ">" + i + "</option>");
   }
0
 

Author Comment

by:adnan_rais
ID: 9698202
The program still responded with errors
0
 
LVL 27

Expert Comment

by:rrz
ID: 9698205
which line is the problem?  
maybe this one?
>   if(mday.equals(request.getParameter("day"))){  
If browser didn't send  "day" then  NPE would occur.
0
 
LVL 27

Expert Comment

by:rrz
ID: 9698220
Please show us the error message and tell us which line is problem.
0
 

Author Comment

by:adnan_rais
ID: 9698236
The error doesn't point to any particular line... Here is the error code

Apache Tomcat/4.0.3 - HTTP Status 500 - Internal Server Errortype Exception reportmessage Internal Server Errordescription The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.exception java.lang.NullPointerException
 at org.apache.jsp.CreateUser$jsp._jspService(CreateUser$jsp.java:118)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
 at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
 at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
 at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
 at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
 at java.lang.Thread.run(Thread.java:484)

Should there b any change to be made in the page directive by importing any class file
0
 

Author Comment

by:adnan_rais
ID: 9698257
<%@ page language="Java" import="java.sql.*,java.util.*,java.lang.*" %>
0
 
LVL 27

Expert Comment

by:rrz
ID: 9698258
Just an idea, instead of
>    <option value="none">Day</option>
use
<option value="none" selected="selected">Day</option>
0
 

Author Comment

by:adnan_rais
ID: 9698271
no rrz@871311, ur idea didn't help
0
 
LVL 27

Expert Comment

by:rrz
ID: 9698273
>java.lang.NullPointerException
 at org.apache.jsp.CreateUser$jsp._jspService(CreateUser$jsp.java:118)

Look in Tomcat's work directory for  CreateUser$jsp.java
0
 

Author Comment

by:adnan_rais
ID: 9698288
how to get into it?
0
 
LVL 27

Expert Comment

by:rrz
ID: 9698296
>Should there b any change to be made in the page directive by importing any class file    
No, that would not create a NPE.
0
 
LVL 27

Expert Comment

by:rrz
ID: 9698319
Shut down Tomcat to look at work folder.
0
 
LVL 1

Expert Comment

by:yapsing
ID: 9699154
i think sending something over is better solution. like:
http://url?day=something
0
 

Expert Comment

by:Morphuess
ID: 10403577
I've used this to convert int to String and it works for me.

String myString = new String ();
myString = String.valueOf(i);
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question