NullPointerException on out.print (String)

I am using weblogic 4.5.1 and jsp 1.1
          Within a jsp page:
          <% out.print (someString); %>
          When someString is null, the server is throwing a NullPointerException.
          The stack trace reveals that the server is trying to do a
          someString.length() call (Whatever for?). Must you check every string that
          you print our for null before you print it?
          Thanks for the help.
          Tim
          

The 'New to Java' forum is some doors further. Please make use of it for basic questions about the Java SE API which are in fact already answered in the javadocs. This has completely nothing to do with JSP/Servlet.

Similar Messages

  • Printing Strings on same line questions

    I need to know how to print the same number of _ (underscores) as there are letters in a given string. I already have the int of the number of characters in the string but how do i use that to print the same number of underscores in ONE line, not vertically. responses are appreciated.

    In your loop that prints the underscores, use System.out.print("_"), rather than System.out.println("_"). Read the javadocs to see the difference between these two methods.

  • How to output HTML code in methods without out.print

    Hi,
    I am trying to create a larger web-site with jsp. At first I tried to structure the page using include files. Since there is a limit for the length of if/else blocks, I now switched to using methods instead.
    The Problem I have is that there a larger HTML blocks I dont want to print with out.print because that would make the source unreadable.
    Unfortunately the <%= tag doesnt work in methods.
    Here a code sample:
    <%!
    public void processOrder()
    for(int i=1; i<10; i++)
    out.print("<table>");
    out.print("<tr>");
    out.print("<td>Your Order:<td>");
    %>
    Isnt there a way to use a tag like <%= ?
    Or are there other constructs then methods which can handle <%= ?
    With PHP it would be no problem. So I wonder why there should be no way to do it with jsp.

    I generally put dynamic output in a separate class file; you can then either instantiate the class in a scriptlet and call the appropriate method (which can either return a string or do all of your out.prints) or use a jsp:useBean tag.
    Given the following class:
    public class myHTML {
       public myHTML(){}
       public String renderTable(){
          String s = "";
          s += "<TABLE>\n";
          s += "<TR><TD>some content</TD></TR>\n";
          s += "</TABLE>\n";
          return s;
    }You can then do either of the following in your JSP page:
    1.<%
       myHTML mh = new myHTML;
       out.print(mh.renderTable());
    %>2.<jsp:useBean id="somename" class="somepkg.myHTML" scope="request">
    <%=somename.renderTable()%>
    </jsp:useBean>Either will work, and all of the redundant out.print or String concat lines are moved out of the JSP.

  • Problem with national characters calling System.out.print(...)

    I need to develop an application printing spanish characters like "�" (ce trencada) "�", "�", etc.
    The problem is when I type
    System.out.print("�")in my application, I get "plus-minus" symbol while executing it.
    Anyone can help me, please?
    Thank you in advance.

    check the list of fonts available. You can use the following code for the purpose.
      public static void main(String args[])
            String fonts[] = getFontNames();
            for(int i = 0; i < fonts.length; i++)
                System.out.println(fonts);
    public static String[] getFontNames()
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return ge.getAvailableFontFamilyNames();

  • Problem with this out.print(status.equals(

    Hi i've got another problem.
    The following codes is as follows:
    String status = (String)rs.getString("Status"); //status is either "O" - Open or "C" - closed
    out.print(status)
    out.print(status.equals("O"));
    it returns me FALSE even in my database it is O... I am not sure why.. can someone enlighten me? and it works if i use
    out.print(status.charAt(0) == ('O');
    I am not sure why..
    please reply asap... thanks

    try follows
    out.print(status) ;
    status.trim();
    out.print(status.equals("O"));That won't change anything. status.trim() won't actually change status; it just returns a substring. If you actually want it trimmed, you should do this:
    status=status.trim();
    out.print(status);
    out.print(status.equals("O"));

  • Out.print() in a jsp function

    Hi
    I have a jsp page. I have defined a function in it which requests the farm parameters through request.getParameter() and then print it using out.print() but it displays errors on request and out objects.
    How can I use these objects in functions declared in a jsp page.
    Thanks in advance
    Sajid

    Try Like this
    <%!
    public String aFunction(HttpServletRequest request,JspWriter out){
    String sName = request.getParameter("Name");
    out.println("Hai "+sName+" i think you got it now!!!!!!!!!!");
    %>

  • Out.print(Double.toString(Math.round(7.0))); out.print(Math.round(7.0));

    Hi,
    I want to round off a double vallue and store it in a string.
    but when do string conversion, the result is diiferent.
    Please see the below result.
    How to solve this problem?
    out.print(Double.toString(Math.round(7.0)));
    out.print(Math.round(7.0));
    Result: 7.0 7

    Hello333 wrote:
    I want to round off a double vallue and store it in a string.What is the reason for this? What is the ultimate goal of this process?
    Math round returns a double, not a String, so you can't expect it to behave like a String. If you want to round a number to a String representation, use the String.format(...) / Formatter / printf collection of methods or use a DecimalFormat:
        DecimalFormat df = new DecimalFormat("#");
        System.out.println(df.format(7.0));Edited by: Encephalopathic on Jul 2, 2009 8:57 PM

  • Please help this clueless beginner with out.print syntax....

    Please help a clueless beginner out!!!! :-)
    I'm trying to build a dynamic table that functions as a calendar...(see http://www.oreilly.com/catalog/javacook/chapter/ch18.html for the basic idea and code structure).
    Here's the problem...I want to make each date inside of the table a hyperlink to a new page. I figured out how to create the hyperlinks, but I CAN'T figure out how to create hyperlinks that pass variables to a new page.
    Here's the code that works:
    // Fill in numbers for the day of month.
    for (int i = 1; i <= daysInMonth; i++)
    out.print("<td>");
    out.print("<a href=newpage.jsp>");
    out.print(i);
    out.print("</a>");
    out.print("</td>");
    Here's the code that DOESN'T work....but can serve as pseudo-code for what I want to do:
    // Fill in numbers for the day of month.
    for (int i = 1; i <= daysInMonth; i++)
    out.print("<td>");
    out.print("<a href=newpage.jsp?year=<%= yy %>&month=<%= months[mm] %>&date=<%= i %>>");
    out.print(i);
    out.print("</a>");
    out.print("</td>");
    <%= yy %>, <%= months[mm] %> are defined elsewhere in the code, and I want to use the current value of "i" from the loop.
    So, if everything works like I want, the table will get created, and if yy=2002 and mm=January, then the hyperlinks will look like:
    for day 1:
    "/newpage.jsp?year=2002&month=January&date=1"
    for day 2:
    "/newpage.jsp?year=2002&month=January&date=2"
    ...for day 31:
    "/newpage.jsp?year=2002&month=January&date=31"
    Can someone please point me in the right direction? Is it even possible to do what I want? (I assume it is...but maybe I can't use out.print???)
    Thanks!

    Hi. The expression "<%=some_Java_expression %>" is the JSP tag, that returns string value to HTML code. You should use it in HTML block like:
    <%String myname="Ivan"; %>
    <body>
    <p>My name is: <%=myname %></p>
    But You tried to use it inside the string expression and it generated some code like this:
    <a href="newpage.jsp?year=<%=yy%">...
    , didn't it?
    It invokes method out.print(" ... "), that prints this string value (but in the HTML block). So You tried to print something inside the print method. You should rewrite Your code like this:
    for (int i = 1; i <= daysInMonth; i++)
    out.print("<td>");
    out.print("<a href=newpage.jsp?year="+yy+"&month="+months[mm]+"&date="+i+">");
    out.print(i);
    out.print("</a>");
    out.print("</td>");
    I used the + operator to join Your code for link tag with the values (yy, months[mm], i.
    I hope it helps You,
    bye.</a>

  • J2me sdk 3.0  problems in System.out.print

    Hi
    I can not use println to print Chinese .
    First I just use System.out.print("test") to print some debug information , and I surprised to find it print nothing.
    Then I try System.out.println("test") and it worked well. But there still problem when print Chinese,
    like System.out.println("&#27979;&#35797;") and it just print a mistake string as "??" !
    Can some tell me how to solved it, thanks .

    Note: This thread was originally posted in the [Sun Java Wireless Toolkit|http://forums.sun.com/forum.jspa?forumID=82] forum, but moved to this forum for closer topic alignment.

  • Out.print() error

    Hi am working on a jsp page which when ran gives an error:
    "An error occurred at line: 58 in the jsp file: /BPMProcess.jsp
    out cannot be resolved"
    What could be the problem. I am s newbie. :)
    thanks
    <%@ page language="java" import="com.metastorm.ework.ecl.tp.*,com.metastorm.ework.ecl.*,com.metastorm.ework.ecl.forms.*,java.io.*"%>
    <html>
    <head>
    <title>
    Data submission
    </title>
    </head>
    <body bgcolor="#ffffff">
    <%
              String txtname;
              String txtpw;
              txtname= request.getParameter("txtname");
              txtpw= request.getParameter("txtpw");
              try
                   ESession eWorkSession = new ESession();
                   login(eWorkSession,txtname,txtpw);
              catch(ETPException e)
                   ETPException nextException = e.getNextException();
                   String      error = "";
                   while (null != nextException)
                        error += nextException.toString();
                        nextException = nextException.getNextException();
    %>
    <%!
         void login(ESession eWorkSession, String username, String password) throws ETPException
              out.print("<h1>Welcome back "+username+"</h1>");
              try
                   eWorkSession.login ( username, password);
              catch(ETPException e)
                   ETPException nextException = e.getNextException();
                   String      error = "";
                   while (null != nextException)
                        error += nextException.toString();
                        nextException = nextException.getNextException();
    %>
    </body>
    </html>

    so something like this ?
    <%@ page language="java" import="com.metastorm.ework.ecl.tp.*,com.metastorm.ework.ecl.*,com.metastorm.ework.ecl.forms.*,java.io.*"%>
    <html>
    <head>
    <title>
    Data submission
    </title>
    </head>
    <body bgcolor="#ffffff">
    <%
              String txtname;
              String txtpw;
              txtname= request.getParameter("txtname");
              txtpw= request.getParameter("txtpw");
              try
                   ESession eWorkSession = new ESession();
                   login(eWorkSession,txtname,txtpw);
                   out.print("<h1>Welcome back "+txtname+"</h1>");
              catch(ETPException e)
                   ETPException nextException = e.getNextException();
                   String      error = "";
                   while (null != nextException)
                        error += nextException.toString();
                        nextException = nextException.getNextException();
    %>
    <%!
         void login(ESession eWorkSession, String username, String password) throws ETPException
              try
                   eWorkSession.login ( username, password);
              catch(ETPException e)
                   ETPException nextException = e.getNextException();
                   String      error = "";
                   while (null != nextException)
                        error += nextException.toString();
                        nextException = nextException.getNextException();
    %>
    <%= username %>
    </body>
    </html>
    that gives me an error:
    An error occurred at line: 80 in the jsp file: /BPMProcess.jsp
    username cannot be resolved
    77:
    78:
    79: %>
    80: <%= username %>
    81:
    82: </body>
    83:

  • Out.print written to portlet within portal w/out redirect

    I am trying to write output to only just the portlet portion of the portal
    without having to do a redirect. What am I missing? The following is my
    portlet JSP:
    <!-- Copyright (c) 2000 by BEA Systems, Inc. All Rights Reserved. -->
    <%@ page extends="com.beasys.commerce.portal.admin.PortalJspBase"%>
    <%@page import ="java.lang.String" %>
    <%@page import ="java.util.*" %>
    <%@page import ="java.net.*" %>
    <%@page import ="java.io.*" %>
    <%
    try {
    StringBuffer sb = new
    StringBuffer("http://localhost:8080/servlet/com.clickaction.erm.events.Event
    Servlet?test=test");
    for(Enumeration e = request.getParameterNames(); e.hasMoreElements(); ){
    String parameterName = (String)e.nextElement();
    sb.append("&" + java.net.URLEncoder.encode(parameterName) + "=" +
    java.net.URLEncoder.encode(request.getParameter(parameterName)));
    String
    host="http://localhost:8080/servlet/com.clickaction.erm.events.EventServlet?
    com.clickaction.erm.events.EventHandler.EVENT.0=com.clickaction.erm.events.T
    ransformerEvent&com.clickaction.erm.events.TransformerEvent.FILE=xml/surveys
    /surveyresponsetransforms.xml&clientID=llbean&userID=abcd";
    URL servletURL = new URL(sb.toString());
    URLConnection con = servletURL.openConnection();
    con.setDoInput(true);
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type", "text/html");
    InputStream in = con.getInputStream();
    BufferedReader serverStream = new BufferedReader(new InputStreamReader(in));
    String receiveString;
    while((receiveString = serverStream.readLine()) != null){
    out.print(receiveString);
    in.close();
    } catch (Exception e){
    System.out.println("The connection is dead");
    response.sendRedirect("http://localhost:7601/mybuybeans");
    %>

    Why can't you do
    class Destination
    private static Destination d = new Destination();
    public static Destination getDestination()
    return d;
    private Destination()
    public void otherMethods()
    Now your go between just calls.
    Destination.getDestination().otherMethods();

  • How do you overwrite System.out.print()

    I am sure there is a way to over write the last entry to System.out.print ?
    I think it is by using an escape sequence (eg \t or \n), but cant work out which letter to use.
    can any one help?
    Simon

    It's \r:
    class Overwrite {
         public static void main(String[] args) {
              System.out.print("Old Text");
              System.out.print("\rNew");
    }

  • Need help, trying to print strings backwards while ignoring certain things.

    To clarify the topic what I mean is I want to spell the words the user inputs backwards while skipping over certain characters. Here's my code:
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    import java.io.*;
    class SConvert{
    private static final char BLANK = ' ';
    private static final String stop = "STOP";
    public static void main(String[] args){
    char[] ignore = new char[21];
    ignore[0] = '.';
    ignore[1] = '/';
    ignore[2] = '>';
    ignore[3] = '<';
    ignore[4] = ',';
    ignore[5] = '?';
    ignore[6] = '-';
    ignore[7] = '~';
    ignore[8] = '!';
    ignore[9] = '@';
    ignore[10] = '#';
    ignore[11] = '$';
    ignore[12] = '*';
    ignore[13] = '&';
    ignore[14] = '^';
    ignore[15] = '%';
    ignore[16] = '`';
    ignore[17] = '_';
    ignore[18] = '+';
    ignore[19] = '=';
    ignore[20] = '|';
    String word, statement, append;
    boolean go = true;
    int i, numOfchar, index;
    char[] chr;
    index = 0;
    word = " ";
    statement = " ";
    append = " ";
    Scanner scanner = new Scanner(System.in);
    while (go){
    System.out.println("Enter a word");
    word = scanner.next();
    chr = word.toCharArray();
    numOfchar = word.length();
    if (word.equals(stop)){
         break;
    else if (index < numOfchar && word.charAt(index) == BLANK + BLANK){
         index = BLANK;
    else if (index < numOfchar && word.charAt(index) == (int)ignore[19]){ //Trying to range for entire array, I don't know how.
         index++;
    else
           for (i = word.length() - 1; i >= 0; i--)
              statement = statement + chr;
              append = append + " " + statement;
    System.out.print(append + " ");
    What's messing me up is the fact that whenever I try to enter words into the program, printing append only repeat EVERY occurance of statement. For example, say I type in "Ham with gravy." I get "maH htiwmaH yvarghtiwmaH".
    That's not what I want. Also, I don't know how to make the entire array of ignore available to the program, anyway to do that?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Wow. What's with the hostility? Even I was in error of detecting anything that could have solve the problem completely there's no need to use such a negative tone, epsecaility with someone who is learning to program in OOP, let alone the syntax of Java. Also, no your program did not solve all of my problems in it's original form. Let's take a look at it.
    Here's your code:
    import java.lang.String;
    import java.util.*;
    public class ReverseString {
      public void ReverseString(){
      public void printReverse(String s){
         int i;
        String noPrint = "no print'";
        char ch = '*';
        if(s.length()>1) printReverse(s.substring(1));
         ch = s.charAt(0);
        if (!noPrint.contains(ch + " ")) System.out.print(ch);
        return;
      public static void main(String[] args) {
          String myString = Here is my String.;
       System.out.print("My String: " + myString + " Reverse: ");
       new ReverseString().printReverse(add);
       System.out.println();
    }In it's original state the program doesn't allow for any user input, which is something I needed (and added on my own), it doesn't convert the ignore[] I had in my original code to anything readable (however this can be done in the noprint String quite easy as someone else mentioned earlier.) the if command does in fact ignore the special characters in noprint String HOWEVER it doesn' t not print those characters as they would appear in the myString String in the position that it original appeared in (which is the primary problem I am having.) That is the problem with your code and why it is not the complete to soultion to my homework problem. I've modified your code to satisifed all but one of the problems.
    Modified:
    import java.lang.String;
    import java.util.*;
    public class ReverseString {
      public void ReverseString(){
      public void printReverse(String s){
         int i;
        String noPrint = "~`!@#$%^&()-=+[{]}\':;?/>.<,'";
        char ch = '*';
        if(s.length()>1) printReverse(s.substring(1));
         ch = s.charAt(0);
        if (!noPrint.contains(ch + " ")) System.out.print(ch);
        return;
      public static void main(String[] args) {
           Scanner scanner = new Scanner(System.in);
          String myString;
          String add = " ";
           while (true) {
       System.out.println("Please input String.");
       myString = scanner.next();
       add = add + myString;
              if (myString.equals("STOP")){
                   break;
       System.out.print("My String: " + add + " Reverse: ");
       new ReverseString().printReverse(add);
       System.out.println();
    }If you run this code you'll see what am talking about. The only remaining problem, which I am about to restate if you are still unclear of it, is that the noprint String contents are ignored but not printed in the original position. If you are still having trouble understanding what I am talking about then let me show what I got by running the program.
    String: Ham with grav?y
    Reverse: yvarg htiw maH. [Note the ? is missing.]
    By removing the ! in the if command I get:
    Reverse: y?varg htiw maH. [Now the ? is in the wrong position.]
    It's suppose to be:
    String: Ham with grav?y
    Reverse: yvarg htiw ma?H.
    Secondly, I understand that you are frustrated with my apparent lack of understanding of proper Java tems and syntax but you must keep in mind I am student thus I am not fully aware of java as you are. With that one would expect you to act with a bit more patience, yet you not only took offense to an innocent comment you choose to slander my name and intelligence by erasing your code and calling my understanding of Java, ?ignorant.? I may be less than careful with my choice of words concerning Java but I do understand enough code to know the inner workings of a typical program, so please refrain from calling me ignorant or any variant of this in the future.
    I merely asked for help from general populous, do not think I owe you any particular praise for your code even if I find it is not exactly what I desired. I may be new to java but I am not new the message boards. With that said I find your response awfully rude and ask if you to refrain from do so in the future. I'm assuming you are an adult so act least act like someone with a bit of civility. If you were so committed to believing your code was the de facto solution to this problem then you could have simply asked why I say what I said, if had done so and shown me the error of my statement I would have not taken offense. Instead you choose to throw a fit and deleted your code. I do not know if you are like this around other board members but you should at least show courtesy to all members of this forum regardless of their time here.
    With that said, I think I've all ready found a solution to this problem I've had. I'll just tell the program to simply count over the position the character is in. That way it will stay in the same position.

  • How to create a class like System.out.print

    Hi,
    I need to create a class like System.out.print
    Say for ex: i have a class A ..
    I need to call it A.b.c
    cis the method..
    could you tell me, how can i do this..
    AMJ

    class A{
    public static final B b=new B();
    class B{
    public String getXXX(){
    return "Callled getXXX()";
    public class C{
    public static void main(String[] args)
    System.out.println(A.b.getXXX());
    }

  • Use of formatting when printing strings

    I would like to know how to print a string that is italicized. I am open to ideas involving complicated methods .. good to learn something new.

    831334 wrote:
    Well I am a graduate student in Computer Science currently building from scratch a database program as part of my school database class I am taking this semester. I have taken undergraduate courses in Java covering simple types, and data structures; at the graduate level algorithm analysis covering topics such as Fourier Transforms. I am also engaged in improving my C programming skills and learning Python to boot.Well that's nice for you, but I doubt many will be impressed here.
    When I originally posted I thought I would receive an answer to my question regardless where I posted; perhaps this forum would be more active and relevant for my question. Now that my resume is out there including a background in electrical engineering, should I hit Google or can I get an answer to my question?Now I know that one shouldn't expect much eloquence from a computer scientist, but your original question of "How can I print Strings in italics" wasn't exceptionally well thought out. Or was it news to you that Java is capable of outputting Strings in more ways than outputting to a standard console?
    If not the current adage is: "Its easy, just Google it" will suffice and follows the wade through data overload but oh well.We gave you plenty of answers already, do we need to hold a lecture for you to understand them?

Maybe you are looking for

  • The growth of the internet routing table + LISP

    I have been challenged with the task of putting together a 15-20 minute presentation of how I might go about solving the problem of the growth of the internet routing table. If I am understanding the question correctly - as the internet grows so will

  • Bad performance view on views

    we have two views with equal key fields which perform very good (order less than 1 second). Both views give extra fields from data sets. I want to combine those extra fields in one record with equal key values. Because some key combinations can miss

  • Why is the iTunes view all jacked up with this update?

    I'm a big fan of the list... and now I can't view as list unless I click on Songs.  But that's the crappiest way to sort, so it doesn't help me out at all.  Anyone know of a solution to this new view?

  • Using sets with Strings

    Hello, I'm in a dilemma here I'm using a Set to store Strings: private Set<String> X; I have a class that receives a String and first check if the string is allready on the set and if not it adds it: public boolean method (V e) { if(X.contains(e.getS

  • How do I turn off the menu audio?

    I love my new Apple TV, everything works well but I hate the voice in the menu telling me everything that I can read. Is there a way to turn it off?