aspose file tools*
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
Author

PLEASE HELP --- Java Newbie!!!

b rag
Greenhorn

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) {
try
{
HttpServletRequest request=null;
request.setAttribute("fdfs","fdfsdf");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60055
    
  65

HttpServletRequest request=null;
request.setAttribute("fdfs","fdfsdf");


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
Greenhorn

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

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PLEASE HELP --- Java Newbie!!!
 
Similar Threads
Thread Safe classes
Exception in thread "main" org.xml.sax.SAXException
Problem deplying struts application in weblogic
Needed jar files to use SAX
JDK 1.5 MetaData