This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Hello World servlet in VAJava 4.0

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is anyone familiar with VisualAge Java 4.0? I am trying to get a simple Hello World servlet to run on the Websphere Test Environment.
- The sample servlets run fine
- I have placed the following code in the default_app/servlets/sampleservlets subdirectory (This servlet was created in the sampleservlets package in VAJava):
package sampleservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* Insert the type's description here.
* Creation date: (10/26/2001 3:04:49 PM)
* @author: Administrator
*/
public class HelloWorld extends HttpServlet {
/**
* HelloWorld constructor comment.
*/
public HelloWorld() {
super();
initialize();
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(java.lang.Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
// user code begin {2}
// user code end
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
HelloWorld aHelloWorld;
aHelloWorld = new HelloWorld();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.servlet.http.HttpServlet");
exception.printStackTrace(System.out);
}
}
/**
* service method comment.
*/
public void service(javax.servlet.ServletRequest arg1, javax.servlet.ServletResponse arg2) throws javax.servlet.ServletException, java.io.IOException {}
}

When I try to run the servlet, using http://localhost:8080/servlet/sampleservlets/HelloWorld, I get the following message:
Message: Server caught unhandled exception from servlet [invoker]: Servlet [sampleservlets]: Could not find required servlet class - sampleservlets.class

ANY THOUGHTS??
------------------
John
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dod you configure the default_app file?
If you are not going to reference the servlet with the full package name you should have configured the server to take HelloWorld servlet without the package name in from of the servlet name.
Thats just a thought. I might be totally wrong.
Faze
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that you haven't mentioned what Project your servlet is in makes me believe that the source code isn't in VAJ. Is this true? How did you create this servlet, and what project did you create it in? Did you then add that project to the classpath of the WTE?
Kyle
P.S. I walk through this entire process in gory detail in my book (below)
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
john way
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Kyle Brown:
[B]The fact that you haven't mentioned what Project your servlet is in makes me believe that the source code isn't in VAJ. Is this true? How did you create this servlet, and what project did you create it in? Did you then add that project to the classpath of the WTE?
Yes, I have done all the above. I created a project called JohnsProject and added that project to the classpath using the WTE control center.
The next thing I tried was to create a new package in the IBM JSP Examples project called com.ibm.ivj.wte.samples.johnway I created a new servlet, cut out the auto generated code and pasted my HelloWorld code (shown in original post)into this new class (with the same name)
when I called the URL from my browser with http://localhost:8080/servlet/com.ibm.ivj.wte.samples.johnway.HelloWorld I get a blank email page. View-Source gives me the following
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
Which is obviuosly not what I programmed, but it is something. Any thoughts on what I need to do to get the desired output programmed in HelloWorld?
------------------
John

 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
I'm sorry, but I'm still confused. Is your new servlet in the IBM JSP Examples project or your new JohnsProject project or both? I can't quite tell from your posting...
Kyle
BTW, you shouldn't have to file the servlet code out into the directory structure of VAJ...
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, geez. Now I see it. You've overridden the service() method to do nothing. That's why you're not seeing anything. In the superclass HttpServlet service() is implemented to call doPost() on an HTTP POST request or doGet() on an HTTP GET request. You don't need to override it. Delete the service() method from your class!
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
john way
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did the trick. Thank you very much!! I did have the code in both projects, now they both work fine and I can proceed to try more difficult task.

------------------
John
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are very welcome. I'm glad we could help. If you have any more questions, feel free to go ahead and ask
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
john way
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do have one question. Somehow, I added the service() method to my servlet as well as two of the sample servlets - LookupSign and LeapYear. Any idea what "button" I pushed?
------------------
John
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by john way:
I do have one question. Somehow, I added the service() method to my servlet as well as two of the sample servlets - LookupSign and LeapYear. Any idea what "button" I pushed?


Yes -- there's a check box on the "create servlet" wizard that is for the service() method. Make sure you "uncheck" it for new servlets
Kyle
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!