Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:43:24+00:00 2026-06-04T19:43:24+00:00

I’m trying to output Java to HTML using a CGI script for class. I’m

  • 0

I’m trying to output Java to HTML using a CGI script for class.

I’m wondering why I can’t seem to be able to properly compare the values of the variables that I’m checking for. The code works, but doesn’t manage to compare the variables and doesn’t end the HTML code properly. It somehow never reaches to the end of the code for some reason. (never writes out the ending body and html tags)

post.java

import java.io.*;

public class post {
    public static void main(String [] args) {       
        System.out.println("Content-Type: text/html\n\n");
        System.out.println("<HTML><BODY>");
        System.out.println("<h1>Here is your stupid user report:</h1>");
        String fullname = "";
        String address = "";
        String city = "";
        String state = "";
        String washhands = "";
        String takeshower = "";
        boolean stupidity = false;
        String comments = "";       
        String data = "";
        try {
            BufferedReader br = 
                new BufferedReader(new InputStreamReader(System.in));
            data = br.readLine();
        } catch(IOException ioe) {
          System.out.println ("IOException reading POST data: " + ioe);
        }               
        if (data.length() > 0) {
            String[] paramArray = data.split("&");      
            for(String param : paramArray){
                String[] paramVals = param.split("=");
                String paramName = paramVals[0];
                System.out.println(paramName + "<br/>");
                String paramVal = paramVals[1];
                System.out.println(paramVal + "<br/>");
                if (paramName == "fullname") fullname = paramVal;
                if (paramName == "address") address = paramVal;
                if (paramName == "city") city = paramVal;
                if (paramName == "state") state = paramVal;
                if (paramName == "washhands") washhands = paramVal;
                if (paramName == "takeshower") takeshower = paramVal;
                if (paramName == "stupidity") stupidity = true;
                if (paramName == "comments") comments = paramVal;
            }
            System.out.println("HELLOOOOO");
            if (fullname != ""){
                System.out.println("Here we have <font color=blue>" + fullname + "</font> ");
            }
            if (fullname == ""){
                System.out.println("Here's a <i>nobody</i> ");
            }
            if (address != ""){
                System.out.print("who lives on <font size=20>" + address + "</font> ");
            }
            if (city != ""){
                System.out.print("from the city of <u>" + city + "</u> ");
            }
            if (state != ""){
                System.out.print("in the state of <b><u>" + state + "</u></b> ");
            }
            if (washhands != ""){
                if (washhands == "no") System.out.print("who <b>doesn't</b> wash his/her hands after using the bathroom...");
                if (washhands == "yes") System.out.print("who washes his/her hands after using the bathroom...");
            }
            if (takeshower != ""){
                if (takeshower == "everyday") System.out.println("<center>He/she takes a shower everyday.</center>");
                if (takeshower == "never") System.out.println("<center>He/she never takes a shower.</center>");
            }
            if (stupidity == true){
                System.out.println("<tt>He/she is stupid.</tt>");
            }
            if (comments != ""){
                System.out.println("<h3>Here are what he thinks about this assignment:" + comments + "</h3>");
            }
        }           

        System.out.println("</BODY></HTML>");
    }
}

The CGI file that I’m using – post.cgi (located at /cgi-bin/post.cgi)

#!/bin/sh

java post

The HTML file that I’m using to allow input:
post.html

<html>
<head>
<title>Lab 9 Form</title>
</head>
<body>
<h1>Embarrassing questions form</h1>
<form action="../cgi-bin/post.cgi" method="post" name="embarassmentform">
<label for="fullname">Name</label>
<input type="text" name="fullname" id="fullname" />
<br/><label for="address">Address</label>
<input type="text" name="address" id="address" />
<br/><label for="city">City</label>
<input type="text" name="city" id="city" />
<br/><label for="selectastate">State</label><select name="selectastate">
<option>NY</option>
<option>FL</option>
</select>
<p/>
<label for="washhands">Do you wash your hands after using the bathroom?</label>
<br/><input type="radio" name="wash" value="yes">Yes</input>
<br/><input type="radio" name="wash" value="no">No</input>
<p/>
<label for="takeshower">How often do you take a shower?</label>
<br/><input type="radio" name="shower" value="everyday">Every day</input>
<br/><input type="radio" name="shower" value="never">Never</input>
<p/>
<input type="checkbox" name="stupidity" value="stupid"/><label for="stupidity">Check this box if you're stupid.</label>
<p/>
<label for="comments">Questions and comments can go here</label><br/><textarea name="comments"></textarea>
<br/><input type="submit" name="submitButton" value="Submit the form" />

</form>

</body></html>

If you could please point out anything that is likely the problem… the debug output works, as in it manages to output the variable values, but totally ignores the if statements for some reason.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:43:26+00:00Added an answer on June 4, 2026 at 7:43 pm

    I’m wondering why I can’t seem to be able to properly compare the values of the variables that I’m checking for.

    Because you’re comparing string references for equality, rather than the contents of strings. Every time you use something like:

    if (city != "")
    

    you want:

    if (!city.equals(""))
    

    or if city may be null:

    if (!"".equals(city))
    

    Applying == and != to references always just compares the references in Java – there’s no operator overloading to allow for the contents of the objects to be compared.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.