Solved

Setting up a class, calling it from html or asp

Posted on 2001-08-16
10
240 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 100 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 39
check java version using powershell 13 304
How do I remove an object from a 3 53
Bot application - advice 3 63
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

726 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