wood burning stoves
The moose likes Servlets and the fly likes PLEASE HELP --- Java Newbie!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "PLEASE HELP --- Java Newbie!!!" Watch "PLEASE HELP --- Java Newbie!!!" New topic

PLEASE HELP --- Java Newbie!!!

b rag

Joined: Mar 31, 2005
Posts: 6
GETTING "NullPointer" for this. Please advice.

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class test {
public static void main(String[] args) {
HttpServletRequest request=null;
catch (Exception e)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63208

HttpServletRequest request=null;

You set a variable to null, and then try to call a method on it. Of course, you are going to get a null pointer exceptions.

I think you need to familiarize yourself with basic Java before trying to dive off into Servlet programming.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
b rag

Joined: Mar 31, 2005
Posts: 6
So how do I set a Reuqest Object and set Attributes to it? Thanks,
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You can't from a main method.
Servlets need to be run inside a servlet container, like Tomcat, Websphere, etc..

I would follow the advice given and go through a few Java tutorials before tackling servlets. Then, before posting in a forum, follow some servlet tutorials to get the basics down.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17271

"b rag"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it


Thanks! and welcome to the JavaRanch!


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: PLEASE HELP --- Java Newbie!!!
It's not a secret anymore!