Solved

Converting int to String

Posted on 2003-11-06
17
52,335 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
Comment Utility
String s = new Integer(i).toString();

OR

String s = "" + i;


0
 
LVL 6

Expert Comment

by:kotan
Comment Utility
Integer.toString(i);
0
 

Author Comment

by:adnan_rais
Comment Utility
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
 
LVL 18

Accepted Solution

by:
bobbit31 earned 20 total points
Comment Utility
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
Comment Utility
The program still responded with errors
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
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
Comment Utility
Please show us the error message and tell us which line is problem.
0
 

Author Comment

by:adnan_rais
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

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

Expert Comment

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

Author Comment

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

Expert Comment

by:rrz
Comment Utility
>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
Comment Utility
how to get into it?
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
>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
Comment Utility
Shut down Tomcat to look at work folder.
0
 
LVL 1

Expert Comment

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

Expert Comment

by:Morphuess
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now