View Full Version : Path for javax.servlet & other servlet help needed
J.Pluta
05-22-2001, 03:26 PM
Don, you do indeed have a number of issues here. First off, are you running WebSphere on your AS/400 to do your webserving? If so, there are a number of configuration issues, depending on the version of WebSphere you are using. More importantly, if you are using version 3.0 of WebSphere or above (I personally use 3.5), you will need to install the adminclient on a workstation. This workstation must run either Windows NT or Windows 2000. This is the start of your magical adventure <grin>. Tell us more! What version of OS/400? What version of WebSphere? Latest cumes and group PTFs applied? MORE INFORMATION!!!!!!! >grin<
dnmcin@yahoo.com
05-22-2001, 05:54 PM
Hello Joe, we are leasing space on the 400 from a company and I'm the only one working with Java at this time. We have Websphere loaded on an NT Server (I'll have to get back with you on the version)the server currently has the JD Edwards Xe software loaded on it and is in working order, but has not been placed in production as of yet. I thought that this would be a good opportunity to work with Servlets etc (have to learn sometime and somehow). The 400 has r4v4 installed at the present time (we will probably be gettin our own 400 within the next several months). I am currently writing and compiling the Java on a Windows 98 PC using Notepad and DOS to compile. I have gotten JDBC and a few things other classes from the toolbox to work on my PC, haven't tried them yet on the 400(I have compiled a few simple programs on the AS400, it Java is working on it). I have 1.3 on the PC and 1.1.7 of the JDK on the AS400. I was hoping that I would be able to just load a compiled servlet class and and html with a tag to the servlet on the server directory and use the servlet path from a browser to get things going. The servlet is just a simple HelloWorldServlet that I'm starting with. I appreciate the help, I will find out the version of Webshere. Thanks, Don PS as far as cumes and PTF's I have very limited security access on the AS400 here. I'm familiar with PTF's but I'm not familiar with Cumes.
J.Pluta
05-22-2001, 07:43 PM
With a leased AS/400, things get very tricky very quickly. At the risk of telling you things you already know, let me review some basic points real quickly: 1. There are two distinct pieces of software on the host that are used to process servlet requests: the HTTP server and the web application server. The HTTP server on the AS/400 is simply known as the IBM HTTP server (or the IBM Apache HTTP Server on later releases). The web application server is WebSphere. You do not need to have a web application server to serve static web pages or RPG-CGI programs; the web application server is only required for servlets and JavaServer Pages. 2. Everything we're talking about here is part of the browser interface. The browser is the only piece of software on the client. Every time you type in a URL or click on a link, you are making a request to the HTTP server on the host. 3. The browser makes requests according to a protocol known as HTTP (thus the concept of an HTTP server!). This is different from HTML. HTML is (usually) the response from your web server to an HTTP request. In the simplest case, your browser requests a page (via a URL), and the HTTP server sends that page to the browser. 4. There is a tag in the HTML (the APPLET tag) that can launch an applet. Make sure you understand this point: you do not directly request an APPLET. Instead, you request an HTML page, and that page in turn requests an APPLET. 5. On the other hand, a servlet is a program that is requested directly by a URL. What happens is that the URL has some certain pattern (often, but not always, the directory named "servlet" is in the URL) which is recognized by the HTTP server, who in turn passes the request to the web application server. The web application server then loads the servlet, if not already loaded, and runs it. The servlet then is expected to output HTML back to the browser. 6. A servlet is a Java program that runs in a JVM (Java Virtual Machine) on the web host, not the client. In contrast, an applet is loaded from the host, but runs on the client. The applet runs in a special JVM inside the browser on the client. 7. Wherever WebSphere is running is the web host. If you want to play with servlets on the NT box, you can. Or if you want to play with them on the AS/400, you'll have to have WebSphere running on the AS/400. However, the AS/400 HTTP server is not by default configured to run servlets and JavaServer Pages. You must turn on this capability by configuring the HTTP server through a special browser page, which is on port 2001 of your AS/400. 8. Finally, you must configure WebSphere itself. How WebSphere is configured depends on the version. For version 2.0 of WebSphere, it was done using a special browser page, while for WebSphere 3.0 and above a special program, called the adminclient, must be run. This program will only run on an NT or Windows 2000 box. Okay, enough background. Let's say you finally get a HelloWorldServlet written. What is required to actually run it? Well, you have to put it in a specific directory on the AS/400 (which directory depends entirely on your version of WebSphere and how it is configured). The easiest way to get started (how I did it) is to find where WebSphere puts its example servlets, and copy yours there. So, if you're planning on running servlets on the AS/400, the VERY first thing you want to do is find out whether the WebSphere examples work. Once those work, you can then pop your servlet into the WebSphere example directory and get it running. As for the cume and group PTFs, no AS/400 product I've worked with has had so many enhancements in so little time, and because of that, it is essential that you are on the latest cumes and group PTFs for your version of the operating system. Especially for WebSphere 3.5, because if you're not, chances are you won't be able to get your adminclient to run, and without that you won't be able to do much of anything else. Hope this rather longwinded dissertation didn't scare you... perhaps it will help a little bit. Joe
dnmcin@yahoo.com
05-23-2001, 05:36 AM
Hello Joe, I don't mind you being as basic as you want to be. I'm a 1 semester graduate of Java from a Juco, and have written some basic Applets, etc, but no servlets and almost no as400 java other than some small test applications such as I'm doing now. I am under a disadvantage in regards to the as400, I don't even have authority to run dspptf. And to call and ask is possible, but usually met with an unfriendly attitude. (We will probably be getting our own I series sometimes in October). How do I check for cumes? (so I'll know what else I can't do) Since I am currently trying to work with websphere that is installed on the NT, is the 400 info important for now? I am assuming that the JD Edwards software which is a web application using Java servlets, C+, and accessing as400 files is already up and working, that the server would be configured for servlets, and everything would be good to go. When you say thatAdminClient needs to run, are you not saying that I just need server read/write access? Would this (adminclient) not also be running if our JD Edwards software is active? I found out that we're at 3.0.1 level of the websphere app server. As far as being discouraged? It would be nice for everything to be as easy as I was hoping, but I am determined to become a Java developer, and I'll keep plugging away until I get it! Again, thanks for the help. Don
J.Pluta
05-23-2001, 06:53 AM
Well, first off, you've got the right attitude. While it seems daunting at first, you'll find that this is not rocket science, and that in fact most of the things actually make sense (although it's sometimes an slightly twisted kind of sense <grin>). In your situation, I'd certainly suggest working with the NT box to start with. This is a problem as far as my help is concerned, since I haven't upgraded my NT box for a while. If you can hold on for a couple of days, I'll see what I can do along those lines. However, you MAY be able to get some information by looking at the JDE package. 1. Play around with the JDE application, trying to find a URL that has the word "servlet" in it. It may show up in the browser URL display. If not, it may show up when you roll your mouse over the links and buttons in the package. The only way to process a FORM post is through a servlet or CGI program, so on any page that accepts data, the buttons should point to a servlet. 2. Look at the URL. It might be something like: http://yourNTbox/somedir/servlet/anotherdir/servletname?parm1=avalue&parm2=a nothervalue It may NOT follow this pattern, and not all the pieces may be there. The entire URL could be as short as "//yourNTbox/serlvet/servletname". Notice that part of the URL is the name of your NT box, followed by a one or more directories (one of which is usually "servlet"), followed by the servlet name and optionally some parameters. The "servletname" portion is actually the name of the servlet that will be invoked (the class name will be "servletname.class"). NOTE: if one of the directories is something like "cgi-bin", then you're running CGI, not servlets, and life is more difficult. 3. Now that we have the name of the servlet, we need to find out where it is physically located on the NT box. Do a file search on the NT box, looking for "servletname.class". If you find it in one and only one directory, we're in business. Copy your servlet into that directory, then invoke it. Assuming the name of it is HelloWorldServlet.class, then try the following: http://yourNTbox/somedir/servlet/anotherdir/HelloWorldServlet Notice that if there are no directories either before or after the "servlet" directory, then leave them out here, too. Anyway, that's the kludge way of doing things until we bring your knowledge level up a little bit. Note that the physical directory paths, especially right up to the servlet directory, may not match exactly what is in the URL. There is a process called "mapping" that maps the URL path to a physical path on your disk. That's why we had to do the search to find where "servletname.servlet" lives. If there are more than one directories with "servletname.class" in it, try each one individually. Let me know how it goes. Joe
dnmcin@yahoo.com
05-23-2001, 07:08 AM
Joe, I can definitly hold on for a couple of days, due to lack of as400 authority and lack of company wide expertise on NT server's (in regard to Java, none of our NT tech's here know anything about Java, servlets, etc) I will probably still be here plugging away trying to make the info that you have already given me work. I do still have the problem in getting my servlet to compile. It can't find the javax.servlet & javax.servlet.http packages when I try to import it. I assume that I need to set another classpath variable to the associated jar file, but I don't know which one or where it is at. I have found the Javadoc on the 2 packages, but I didn't find the path to the package. I even used the winzip to try to locate the package in various jar files on my desktop (windows 98). Thanks don
J.Pluta
05-23-2001, 12:22 PM
<DIV><FONT face=Arial size=2>Which version of Java are you using? If you are using Java 2 Enterprise Edition, there is a jar file called j2ee.jar that has those classes. Otherwise, up on your AS/400 you should find a file called jsdk.jar. It is located in:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT></DIV> <DIV><FONT face=Arial size=2>QIBMProdDataIBMWebASlib</FONT></DIV> <DIV><FONT face=Arial size=2></FONT></DIV> <DIV><FONT face=Arial size=2>That will get you started.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT></DIV> <DIV><FONT face=Arial size=2>Joe</FONT></DIV> <DIV></DIV>
dnmcin@yahoo.com
05-24-2001, 05:23 AM
I am using the Standard 1.3 on Windows 98. It looked to me that the 1.2 Enterprise edition is for Windows NT/2000, will it work for Windows 98? OK, I copied the JSDK.Jar from the AS400 and placed it in the JDK1.3/Lib on my pc. I added a line to my (SetJava.bat) classpath to 'SET CLASSPATH=%CLASSPATH%;C:JAVAJDK1.3LIBJSDK.JAR. I'm going to include the servlet code that I'm trying to compile so that you can see what I'm doing and may come up with a better way to do it. I got the code from a Java Session at Common User Conference. import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorldServlet extends HttpServlet { public void init(ServletConfig c) throws ServletException { super.init(c); // set up configuration, initialize data } public void destroy() { //release resources, etc. } public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println(""); out.println("
dnmcin@yahoo.com
05-24-2001, 05:43 AM
Apparently, there's a limit to the size of the messages that we can post here. The program was cut off toward the end. I had added in the previous post that perhaps I don't understand the import statement as well as I should. I tried several different ones such as import jsdk.Servlet.*, jsdk.javax.Servlet.*, etc. I ordered a book: Inside Servlets by Dustin Calloway (this was recommended by Don Denoncourt at the user conference) this will hopefully keep me from relying on you for all of my future Java Development. This is the code that was cut-off from my browser in my last post. PrintWriter out = res.getWriter(); out.println(""); out.println("
J.Pluta
05-24-2001, 07:13 AM
Don, I highly suggest some introductory Java books, but until you get them, I'll try to do a brief explanation of the import command. "import" and "CLASSPATH" work together to determine which classes are available to your program. For example, let's say you need the following classes: ServletConfig HttpServletRequest BigDecimal In many ways, accessing one of those classes is sort of like calling a program. Now, there are two ways to call a program: specify the library on the call (a fully qualified program name) or add the library to your library list. For example: CALL MYLIB/MYPROG or ADDLIBLE MYLIB CALL MYPROG Right? Well, it's similar for Java. Java has fully qualified and unqualified class names. The fully qualified names of the first three programs are: javax.servlet.ServletConfig javax.servlet.http.HttpServletRequest java.lang.BigDecimal The part that qualifies ServletConfig, for example, is "javax.servlet", and that is known as the "package name". As I said, you could just fully qualify every class and you'd be fine. Or you can "add a library list entry", which in Java programming terms is the import. You type: import javax.servlet.*; This includes all the classes in the javax.servlet package. I hope this helps explain packages and import, at least from the programming side. So where do CLASSPATH and jar files come in? That's for the compiler. Even though you've detailed in your program which packages and/or classes you need, the compiler still needs to find them. The compiler will either look through the current directory structure to find your packages, or will look in specially formatted files called jar (Java ARchive) files to find them. We're going to skip the first option for this discussion. Instead, let's look at jar files. A jar file is basically a ZIP file containing all the classes for one or more packages. The name of the jar file has nothing at all to do with the packages, which is why things get confusing. It just so happens that there are commonly two jar files that contain the javax.servlet and javax.servlet.http packages; these are jsdk.jar and j2ee.jar. jsdk.jar is used with the standard edition of Java, while j2ee.jar is the version for the enterprise edition of Java. In any case, the compiler needs to find one of these two jar files in order to resolve your import statements. It finds the jar file by looking in your CLASSPATH. So, by specifying jsdk.jar (or j2ee.jar) in your CLASSPATH, you will be able to put "import javax.servlet.*" in your source code, which will in turn enable you to use the ServletConfig class. Does this help? Joe
dnmcin@yahoo.com
05-24-2001, 07:46 AM
I thought that I understand what you just explained but apparently not as well as I should, I've written applets, used the java.applet, java.applet, java.awt.event, etc. but I guess that I don't understand necessarily how they're stored. As I mentioned in my earlier post I had already added the classpath as below: 'SET CLASSPATH=%CLASSPATH%;C:JAVAJDK1.3LIBJSDK.JAR. I assumed that doing this was doing what you had just described. The compile still did not find them. Now if I look at the JSDK.Jar from WinZip (do you use something else to see what's in the jar files?) I can see the all the classes that the program is looking for: (i.e. classes Servlet.class, HttpServlet.class, etc.), But where in the picture is 'Javax'? I guess what I'm asking is how do I know what my import path (or Qualifier) to enter, if I locate a jar file containing the Classes that I need?
J.Pluta
05-24-2001, 07:59 AM
Yay! You're starting to get the picture, Don. The import "path" is the path in WinZip (yes, I use WinZip to look at my programs as well). If you look at the "path" column in WinZip for Servlet.class, you should see "/javax/servlet", which indicates that it belongs to the package javax.servlet. Do me a favor. I assume you're trying to compile using the javac command on the command line, right? If so, do the following, one after the other on the same command line, after you've set your CLASSPATH the way you think it should be set: ECHO %CLASSPATH% javac HelloWorldServlet.java (or whatever the name of your class is) Show us the exact results here.
dnmcin@yahoo.com
05-24-2001, 08:15 AM
Thanks Joe, I got it to compile!! You gave me enough information to figure it out myself. I was out of environment space and the classpath didn't get used. How big (or how many entries) can the environment be? Now I'll have to try to use the earlier advise you gave me to try to get it to work. I'll have to look into the NT Server and try to locate other servlets and place this one into it. Then URL to this servlet or check other URL's and do accordingly. This may take some time because other people are involved in initially getting me access to the correct directories. My current access only shows 2 directories on the server and none contain servlets. I appreciate the help and will respond back when I'm able to continue go on and get some results.
J.Pluta
05-24-2001, 08:32 AM
Way to go, Don! I was a little worried at the beginning, but I can see you're like me... you're willing to try things until you get them to work. The next step is to change things one little bit at a time, and see how that affects the result. That way you begin to build empirical knowledge in your brain about how things work. That's what I do, and while it's a bit longer of a process than just reading a book, for some reason, the mistakes are what get burned into my neurons and give me a solid understanding of what's really going on. Good luck, and let me know when I can help. Joe
dnmcin@yahoo.com
05-24-2001, 11:55 AM
Hello, I am trying to key a servlet that uses packages javax.servlet & javax.servlet.http. My compile cannot find the packages. Does anyone know where these reside? Also, this is my 1st servlet and I am not exactly sure how to implement it. will I just place a tag in a html file and copy it to a application server directory, then set the directory path in my browser URN? I can use all the help that I can get. Thanks Don
dnmcin@yahoo.com
05-24-2001, 11:55 AM
I imagine that when I find the Servlet directory and start actually running the servlet, I'll have some questions. (hopefully small problems) As you suggested, after I can get this simple HelloWorldServlet to work, I'll want to try to access objects from the AS400 & process user input, etc. I'll start simple, accessing 1 file, 1 input field etc. Then after all that, I can hopefully become dangerous, even start write Java using all of these new OO (Object Oriented) techniques that I learned in school. 1st things first though, Hello World! Thanks again, Don
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.