?
Solved

Converting int to String

Posted on 2003-11-06
17
Medium Priority
?
52,448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Accepted Solution

by:
bobbit31 earned 80 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 28

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 28

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 28

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 28

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 28

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 28

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
New style of hardware planning for Microsoft Exchange server.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

752 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