File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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: 63540

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] [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: 17276

"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 - iOS Apps
How to Ask Questions the Smart Way FAQ
subject: PLEASE HELP --- Java Newbie!!!
jQuery in Action, 3rd edition