?
Solved

Setting up a class, calling it from html or asp

Posted on 2001-08-16
10
Medium Priority
?
246 Views
Last Modified: 2013-11-23
I am new to Java.  Running this from the command prompt and implementing it to a site are 2 different things!!!  

I have the following compiled into a class.  It works fine from a command prompt "java SendAddress".  I receive the fields below no problem:
/* start
import com.sagent.centrus.*;
import com.sagent.centrus.crp.*;
 
class SendAddress {
    public static void main(String[] args) {
        System.out.println("Send Address");
        try {
 
            // Create the request.
            Request request = new Request();
 
            // Specify the request.
            //    Login information:
            request.setURL("http://Centrus.Sagent.Com/XML");
            request.setUsername("UserName");
            request.setPassword("Password");
 
            //    Specify a record to be matched:
            InputRecord matchRecord = request.getMatchRecordset().addRecord();
            matchRecord.addField("locator", "gdt", "addressLine", "999 18th Street #2740");
            matchRecord.addField("locator", "gdt", "city", "Denver");
            matchRecord.addField("locator", "gdt", "state", "CO");
 
            //    Specify the output layout:
            request.getLayoutFields().addDisplayField("locator", "gdt", "addressLine");
            request.getLayoutFields().addDisplayField("locator", "gdt", "addressLine2");
            request.getLayoutFields().addDisplayField("locator", "gdt", "city");
            request.getLayoutFields().addDisplayField("locator", "gdt", "state");
            request.getLayoutFields().addDisplayField("locator", "gdt", "zip");
            request.getLayoutFields().addDisplayField("locator", "gdt", "zip4");
            request.getLayoutFields().addDisplayField("locator", "gdt", "latitude");
            request.getLayoutFields().addDisplayField("locator", "gdt", "longitude");

          // Property we want to set:
            request.getProperties().addProperty("locator", "gdt", "MIXED_CASE", "TRUE");
 
            // Submit the request.  
            Response response = request.submit();
            if (response.getIsInError()) {
                System.err.println("Response error string: " + response.getErrorString());
            }
 
            // Read the results for this match record.
            OutputRecord outputRecord = response.getRecordset(0).getRecord(0);
 
            if (outputRecord.getIsInError()) {
                System.err.println("Error: " + outputRecord.getErrorString());
            } else {
                System.out.println("Enhanced standardized address:");
                System.out.println(outputRecord.getField("locator", "gdt", "addressLine").getValue());
                System.out.println(outputRecord.getField("locator", "gdt", "addressLine2").getValue());
                System.out.println(outputRecord.getField("locator", "gdt", "city").getValue() + ", " +
                   outputRecord.getField("locator", "gdt", "state").getValue() + " " +
                    outputRecord.getField("locator", "gdt", "zip").getValue()+ "-" +
                    outputRecord.getField("locator", "gdt", "zip4").getValue());
                System.out.println("Latitude: " + outputRecord.getField("locator", "gdt", "latitude").getValue());
                System.out.println("Longitude: " + outputRecord.getField("locator", "gdt", "longitude").getValue());
                System.out.println();
            }
 
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
}
/*end

The class works with 2 .jar files that I have set in my ClassPath.

Here's what I need to do:
Rather than have the addressLine, City, and Zip filled in in the class, I want them to be sent through a User's HTML or ASP page.

Here's what I need from you:
1. The new class (.java) code to compile will take the variables from an HTML/ASP page.
2.  An HTML or ASP page with all the fields in the class.  When click "Submit", sends the info just as the class above does manually, and populates the page with the result.
2.  How in the heck do I set this all up so it will run in IIS?

I told you I was new at this :)




0
Comment
Question by:douglaskarr
[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
  • 7
  • 2
10 Comments
 
LVL 3

Expert Comment

by:Sendoh
ID: 6395333
hi !
would u like to consider JSP ??
think for ur approach is more suitable by using jsp...:)

regards
Sendoh
0
 
LVL 1

Expert Comment

by:nex1999
ID: 6396725
douglaskarr,

 I will try and answer your questions. I take it that you want this to work as a servlet but right now you are not doing it that way. I might try and rewrite your code into a servlet but let me go into your 2 other points.

  1) IIS does not run or handle your servlet code. You need an app server, like Tomcat(free for windows or Unix). I have alos used Suns jsdk2.1 mini app just for testing purposes, it is free also and super easy to setup.

  2)Sound like you dont know how to make a page that passes data to you servlet? Is that what youre after? IF that is the case something very simple like this:

<html>
<head>
<title>Servlet Test</title>
</head>
<body bgcolor="#FFFFFF">
<Form action="http://www.yoursite.com:8080/examples/servlet/AcceptInput" Method=Post>
 <Table>
  <tr>
    <td>Last Name: </td>
    <td><input name="Last Name" align="left" size"15"> </td>
  </tr>

  <tr>
    <td>First Name </td>
    <td><input name="First Name" align="left" size"15"> </td>
  </tr>

  <tr>
    <td>Age: </td>
    <td><input name="Age" align="left" size"2"> </td>
  </tr>
 </Table>
 <input type="submit" name="Submit" value"submit">
 <input type="reset" value=Reset>
</Form>
</body>
</html>

This will pass the values to a servlet named AcceptInput. The servlet look like this:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class AcceptInput extends HttpServlet {
  //process the HTTP Get Request
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
     doPost(request, response);
    }

    public void init(ServletConfig config)
    throws ServletException
    {
      //always pass theServletConfig object to the super class
     super.init(config);

    }

  //process http post request
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
     response.setContentType("text/html");
     PrintWriter out = response.getWriter();
     out.println("<html>");
     out.println("<head><title>Example Write Client Data</title></head>");
     out.println("<body>");

      //Get all the parameter names
     Enumeration parameters = request.getParameterNames();
     String param = null;
   
      //Iterate over the names, getting the parameters
     while( parameters.hasMoreElements() )
     {
          param = (String)parameters.nextElement();
          out.println("<bold>" + param +
          " : " + request.getParameter(param) +
          "</bold><Br>" );
     }

     out.println("</body></html>");
     out.close();
    }

  //get servlet info
    public String getServletInfo()
    {
     return "Get client Info";
    }  
}

  3. as far as rewriting your code into a servlet... well I did not do that yet. I might try tomorrow. The examples I gave you are very simple kinda stupid even but it takes input from a HTML form and passes to a servlet and it writes that data back out. Hope it helps you out. If you cannot find jsdk2.1 and you want it let me know. I could email it.

-Nex
0
 

Author Comment

by:douglaskarr
ID: 6397101
Nex - that's exactly the guidance I was looking for!  I appreciate your time and effort.  I will review and write these up with the fields necessary.

What is the difference between a class and a servlet?

We do have a servlet engine - I can't remember which.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:nex1999
ID: 6398023
douglaskarr,

I am glad you find my information useful.

OK The difference between a class and a servlet? Well A class can be a servlet. It is called a servlet class. Don't mean to sound silly saying that. With java you can make three different types of programs. You can make client-server stand alone programs with/without user interfaces and stuff(by the way that is what you were making). You can make browser based executable programs called applets. These are ok but have lost some popularity they require you downloading them each time and the bigger the program gets the longer the download. Then last Serverside executable code called servlets. I use these quite a bit but everyone is going toward EJB Enterprise Java Beans.

That is my take on it, there is a ton more info out there on this stuff. But you might consider buying one book which is awesome... it is Thinking in Java by Bruce Eckel. His book is great and covers most of the stuff that people want to know.

-Nex
0
 
LVL 1

Expert Comment

by:nex1999
ID: 6411750
Are you still stuck?

Take a look at this: http://www.webdevelopersjournal.com/articles/intro_to_servlets.html

Let me know what is going on k.

-Nex
0
 
LVL 1

Accepted Solution

by:
nex1999 earned 400 total points
ID: 6413616
0
 
LVL 1

Expert Comment

by:nex1999
ID: 6413628
0
 
LVL 1

Expert Comment

by:nex1999
ID: 6417360
0
 

Author Comment

by:douglaskarr
ID: 6423430
Looks like it doesn't like your text!  You can email it to me at doug@payraisecalculator.com
0
 
LVL 1

Expert Comment

by:nex1999
ID: 6426925
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

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