Solved

Converting int to String

Posted on 2003-11-06
17
52,360 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html form inside div 3 96
maven webservice projet error 6 80
javax.naming.NameNotFoundException: Name ... is not bound in this Context. 6 260
runtime exception 2 27
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

805 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