Re: ServletContext NullPointerException

2005-12-27 Thread Stanislav
Tnx! It works just fine :-)

> Hi Stanislav,
>   Use these lines to avoid the NullPointerException
> 
> import javax.servlet.ServletContext;
> import javax.servlet.http.HttpSession;
> 
> 
>HttpSession ses = request.getSession();
>ServletContext cfg = ses.getServletContext();
> 
> Hope this piece of code helps you,
> 
> Thanks & Bye,Ganesh.K
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ServletContext NullPointerException

2005-12-27 Thread ganesh kannusamy
Hi Stanislav,
  Use these lines to avoid the NullPointerException

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;


   HttpSession ses = request.getSession();
   ServletContext cfg = ses.getServletContext();

Hope this piece of code helps you,

Thanks & Bye,Ganesh.K


RE: RE: ServletContext NullPointerException

2005-12-27 Thread Rakesh.Bhat
Hi,

Use 
ServletContext sc = GenericServlet.this.getServletContext(); // as this is a 
method of GenericServlet.

ServletContext sc = this.getServletContext();

This means no need to give servlet. getServletContext();

I am surprise why are u using servlet.get*


Kind regards,

Rakesh Bhat 
PrimeSourcing(tm) 
The Global IT Services  business from i-flex - "Add Value Reduce Risk"
www.iflexsolutions.com/services/services.asp
i-flex solutions limited - Bangalore
Phone : (080) 5759-6873
Email :  Rakesh.Bhat@ iflexsolutions.com


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 27, 2005 3:15 PM
To: user@struts.apache.org
Subject: Fwd: RE: ServletContext NullPointerException
Importance: Low

- Message Forwarded on 27/12/05 10:45 -
From: "Stanislav" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Subject: RE: ServletContext NullPointerException
Date: Tue, 27 Dec 2005 10:44:00 +0100
I'm sorry :-(( I didn't see you code comments.

I changed my code i still get nullpointerexp in the line with servletcontext, 
like servlet context
is null :-( i believe that answer is hidden in definition of class, but i don't 
no sure what is
wrong :-



> Hi,
> 
> you can check your code I marked with arrows. Any way I will explain here 
> also.
> See you have created a Connection obj called con and initialized it with 
> null.however you are
> inside creating one more object on Connection called conn2 and intilaiting it 
> with method
> getConnection. And calling createStatement using conn object of Connection 
> which is initialized to
> null.That is a reason u r getting NUllPointerExp
> 
> Check your code with arrows.
> 
> Kind regards,
> 
> Rakesh Bhat 
> PrimeSourcing(tm) 
> The Global IT Services  business from i-flex - "Add Value Reduce Risk"
> www.iflexsolutions.com/services/services.asp
> i-flex solutions limited - Bangalore
> Phone : (080) 5759-6873
> Email :  Rakesh.Bhat@ iflexsolutions.com
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 27, 2005 2:43 PM
> To: user@struts.apache.org
> Subject: RE: ServletContext NullPointerException
> Importance: Low
> 
> :-))
> 
> I presume that my code is wrong, but i don't know what part :-( Can you help 
> me?
> 
> Tnx,
> Stanislav
> 
> > Hi,
> > Check your code:
> > 
> > 
> > 
> > Kind regards,
> > 
> > Rakesh Bhat 
> > PrimeSourcing(tm) 
> > The Global IT Services  business from i-flex - "Add Value Reduce Risk"
> > www.iflexsolutions.com/services/services.asp
> > i-flex solutions limited - Bangalore
> > Phone : (080) 5759-6873
> > Email :  Rakesh.Bhat@ iflexsolutions.com
> > 
> > 
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> > Sent: Tuesday, December 27, 2005 2:33 PM
> > To: user@struts.apache.org
> > Subject: ServletContext NullPointerException
> > Importance: Low
> > 
> > This is my code:
> > 
> > import java.text.DecimalFormat;
> > import java.text.DecimalFormatSymbols;
> > import java.text.NumberFormat;
> > import java.text.ParseException;
> > import java.util.Calendar;
> > import java.util.GregorianCalendar;
> > import java.util.HashMap;
> > import java.text.DateFormat;
> > import java.util.Date;
> > 
> > import app.Constants;
> > 
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > 
> > import javax.sql.DataSource;
> > import java.sql.Connection; 
> > import java.sql.ResultSet; 
> > import java.sql.Statement; 
> > import java.sql.DriverManager;
> > import java.sql.SQLException;
> > 
> > import org.apache.struts.action.Action;
> > 
> > public class MethodTest extends Action {
> > public void upisULogMetoda (HttpServletRequest request, 
> > HttpServletResponse response, String
> > statusUpisaLoga, String javaKlasa, 
> > String kategorijaUpisa, String 
> > sifraUpisa, String opis) 
> > throws ServletException, IOException
> >  {
> > HttpSession session = request.getSession();
> > 
> > Connection conn = null;
> > Statement stmt = null;
> > ResultSet rs = null;
> > 
> >  try
> > {
> > 
> > ServletContext context = servlet.getServletContext();
> > DataSource dataSource = (DataSource)
> > context.getAttribute("org.ap

Re: ServletContext NullPointerException

2005-12-27 Thread Shiva Narayana
Hi All,

Need Info about WBI(Websphere Business Integration). Basically I am a struts
developer. I have to use WBI tool to get the data from mainframes servers
and has to display the data on webpages using struts. Please give me any
suggestion or reference materials or guidence.

Thanks in advance.


Regards
Shiva


Fwd: RE: ServletContext NullPointerException

2005-12-27 Thread Stanislav
- Message Forwarded on 27/12/05 10:45 -
From: "Stanislav" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Subject: RE: ServletContext NullPointerException
Date: Tue, 27 Dec 2005 10:44:00 +0100
I'm sorry :-(( I didn't see you code comments.

I changed my code i still get nullpointerexp in the line with servletcontext, 
like servlet context
is null :-( i believe that answer is hidden in definition of class, but i don't 
no sure what is
wrong :-



> Hi,
> 
> you can check your code I marked with arrows. Any way I will explain here 
> also.
> See you have created a Connection obj called con and initialized it with 
> null.however you are
> inside creating one more object on Connection called conn2 and intilaiting it 
> with method
> getConnection. And calling createStatement using conn object of Connection 
> which is initialized to
> null.That is a reason u r getting NUllPointerExp
> 
> Check your code with arrows.
> 
> Kind regards,
> 
> Rakesh Bhat 
> PrimeSourcing(tm) 
> The Global IT Services  business from i-flex - "Add Value Reduce Risk"
> www.iflexsolutions.com/services/services.asp
> i-flex solutions limited - Bangalore
> Phone : (080) 5759-6873
> Email :  Rakesh.Bhat@ iflexsolutions.com
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 27, 2005 2:43 PM
> To: user@struts.apache.org
> Subject: RE: ServletContext NullPointerException
> Importance: Low
> 
> :-))
> 
> I presume that my code is wrong, but i don't know what part :-( Can you help 
> me?
> 
> Tnx,
> Stanislav
> 
> > Hi,
> > Check your code:
> > 
> > 
> > 
> > Kind regards,
> > 
> > Rakesh Bhat 
> > PrimeSourcing(tm) 
> > The Global IT Services  business from i-flex - "Add Value Reduce Risk"
> > www.iflexsolutions.com/services/services.asp
> > i-flex solutions limited - Bangalore
> > Phone : (080) 5759-6873
> > Email :  Rakesh.Bhat@ iflexsolutions.com
> > 
> > 
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> > Sent: Tuesday, December 27, 2005 2:33 PM
> > To: user@struts.apache.org
> > Subject: ServletContext NullPointerException
> > Importance: Low
> > 
> > This is my code:
> > 
> > import java.text.DecimalFormat;
> > import java.text.DecimalFormatSymbols;
> > import java.text.NumberFormat;
> > import java.text.ParseException;
> > import java.util.Calendar;
> > import java.util.GregorianCalendar;
> > import java.util.HashMap;
> > import java.text.DateFormat;
> > import java.util.Date;
> > 
> > import app.Constants;
> > 
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > 
> > import javax.sql.DataSource;
> > import java.sql.Connection; 
> > import java.sql.ResultSet; 
> > import java.sql.Statement; 
> > import java.sql.DriverManager;
> > import java.sql.SQLException;
> > 
> > import org.apache.struts.action.Action;
> > 
> > public class MethodTest extends Action {
> > public void upisULogMetoda (HttpServletRequest request, 
> > HttpServletResponse response, String
> > statusUpisaLoga, String javaKlasa, 
> > String kategorijaUpisa, String 
> > sifraUpisa, String opis) 
> > throws ServletException, IOException
> >  {
> > HttpSession session = request.getSession();
> > 
> > Connection conn = null;
> > Statement stmt = null;
> > ResultSet rs = null;
> > 
> >  try
> > {
> > 
> > ServletContext context = servlet.getServletContext();
> > DataSource dataSource = (DataSource)
> > context.getAttribute("org.apache.struts.action.DATA_SOURCE");
> >Connection conn2 = dataSource.getConnection(); <
> > 
> > 
> > 
> > stmt = conn.createStatement();  <--- it should be conn2 
> > not conn.(I guess
> > this is the reason )
> > String test = "INSERT INTO .";
> > stmt.executeUpdate(test);
> > stmt.close();
> > 
> > conn.commit();
> > conn.close();
> > 
> > 
> > }
> > catch(Exception e)
> > {
> > // ISKOCI I PRIKAZI PORUKU 
> >

RE: ServletContext NullPointerException

2005-12-27 Thread Rakesh.Bhat
Hi,

you can check your code I marked with arrows. Any way I will explain here also.
See you have created a Connection obj called con and initialized it with 
null.however you are inside creating one more object on Connection called conn2 
and intilaiting it with method getConnection.
And calling createStatement using conn object of Connection which is 
initialized to null.That is a reason u r getting NUllPointerExp

Check your code with arrows.

Kind regards,

Rakesh Bhat 
PrimeSourcing(tm) 
The Global IT Services  business from i-flex - "Add Value Reduce Risk"
www.iflexsolutions.com/services/services.asp
i-flex solutions limited - Bangalore
Phone : (080) 5759-6873
Email :  Rakesh.Bhat@ iflexsolutions.com


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 27, 2005 2:43 PM
To: user@struts.apache.org
Subject: RE: ServletContext NullPointerException
Importance: Low

:-))

I presume that my code is wrong, but i don't know what part :-( Can you help me?

Tnx,
Stanislav

> Hi,
> Check your code:
> 
> 
> 
> Kind regards,
> 
> Rakesh Bhat 
> PrimeSourcing(tm) 
> The Global IT Services  business from i-flex - "Add Value Reduce Risk"
> www.iflexsolutions.com/services/services.asp
> i-flex solutions limited - Bangalore
> Phone : (080) 5759-6873
> Email :  Rakesh.Bhat@ iflexsolutions.com
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 27, 2005 2:33 PM
> To: user@struts.apache.org
> Subject: ServletContext NullPointerException
> Importance: Low
> 
> This is my code:
> 
> import java.text.DecimalFormat;
> import java.text.DecimalFormatSymbols;
> import java.text.NumberFormat;
> import java.text.ParseException;
> import java.util.Calendar;
> import java.util.GregorianCalendar;
> import java.util.HashMap;
> import java.text.DateFormat;
> import java.util.Date;
> 
> import app.Constants;
> 
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> import javax.sql.DataSource;
> import java.sql.Connection; 
> import java.sql.ResultSet; 
> import java.sql.Statement; 
> import java.sql.DriverManager;
> import java.sql.SQLException;
> 
> import org.apache.struts.action.Action;
> 
> public class MethodTest extends Action {
> public void upisULogMetoda (HttpServletRequest request, 
> HttpServletResponse response, String
> statusUpisaLoga, String javaKlasa, 
> String kategorijaUpisa, String 
> sifraUpisa, String opis) 
> throws ServletException, IOException
>  {
> HttpSession session = request.getSession();
> 
> Connection conn = null;
> Statement stmt = null;
> ResultSet rs = null;
> 
>  try
> {
> 
> ServletContext context = servlet.getServletContext();
> DataSource dataSource = (DataSource)
> context.getAttribute("org.apache.struts.action.DATA_SOURCE");
>Connection conn2 = dataSource.getConnection(); <
> 
> 
> 
> stmt = conn.createStatement();  <--- it should be conn2 
> not conn.(I guess this
> is the reason )
> String test = "INSERT INTO .";
> stmt.executeUpdate(test);
> stmt.close();
> 
> conn.commit();
> conn.close();
> 
> 
> }
> catch(Exception e)
> {
> // ISKOCI I PRIKAZI PORUKU 
> e.printStackTrace();
> }
> finally
> {
> try { if (rs != null) rs.close(); } catch (SQLException 
> ignoreThis) {}
> try { if (stmt != null) stmt.close(); } catch (SQLException 
> ignoreThis) {}
> try { if (conn != null) conn.close(); } catch (SQLException 
> ignoreThis) {}
> }
> 
> }
> 
> }
> 
> In the line: ServletContext context = servlet.getServletContext();
> 
> i get NullPointerException. Why?
> 
> Tnx,
> Stanislav
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: ServletContext NullPointerException

2005-12-27 Thread Stanislav
:-))

I presume that my code is wrong, but i don't know what part :-( Can you help me?

Tnx,
Stanislav

> Hi,
> Check your code:
> 
> 
> 
> Kind regards,
> 
> Rakesh Bhat 
> PrimeSourcing(tm) 
> The Global IT Services  business from i-flex - "Add Value Reduce Risk"
> www.iflexsolutions.com/services/services.asp
> i-flex solutions limited - Bangalore
> Phone : (080) 5759-6873
> Email :  Rakesh.Bhat@ iflexsolutions.com
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, December 27, 2005 2:33 PM
> To: user@struts.apache.org
> Subject: ServletContext NullPointerException
> Importance: Low
> 
> This is my code:
> 
> import java.text.DecimalFormat;
> import java.text.DecimalFormatSymbols;
> import java.text.NumberFormat;
> import java.text.ParseException;
> import java.util.Calendar;
> import java.util.GregorianCalendar;
> import java.util.HashMap;
> import java.text.DateFormat;
> import java.util.Date;
> 
> import app.Constants;
> 
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> import javax.sql.DataSource;
> import java.sql.Connection; 
> import java.sql.ResultSet; 
> import java.sql.Statement; 
> import java.sql.DriverManager;
> import java.sql.SQLException;
> 
> import org.apache.struts.action.Action;
> 
> public class MethodTest extends Action {
> public void upisULogMetoda (HttpServletRequest request, 
> HttpServletResponse response, String
> statusUpisaLoga, String javaKlasa, 
> String kategorijaUpisa, String 
> sifraUpisa, String opis) 
> throws ServletException, IOException
>  {
> HttpSession session = request.getSession();
> 
> Connection conn = null;
> Statement stmt = null;
> ResultSet rs = null;
> 
>  try
> {
> 
> ServletContext context = servlet.getServletContext();
> DataSource dataSource = (DataSource)
> context.getAttribute("org.apache.struts.action.DATA_SOURCE");
>Connection conn2 = dataSource.getConnection(); <
> 
> 
> 
> stmt = conn.createStatement();  <--- it should be conn2 
> not conn.(I guess this
> is the reason )
> String test = "INSERT INTO .";
> stmt.executeUpdate(test);
> stmt.close();
> 
> conn.commit();
> conn.close();
> 
> 
> }
> catch(Exception e)
> {
> // ISKOCI I PRIKAZI PORUKU 
> e.printStackTrace();
> }
> finally
> {
> try { if (rs != null) rs.close(); } catch (SQLException 
> ignoreThis) {}
> try { if (stmt != null) stmt.close(); } catch (SQLException 
> ignoreThis) {}
> try { if (conn != null) conn.close(); } catch (SQLException 
> ignoreThis) {}
> }
> 
> }
> 
> }
> 
> In the line: ServletContext context = servlet.getServletContext();
> 
> i get NullPointerException. Why?
> 
> Tnx,
> Stanislav
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: ServletContext NullPointerException

2005-12-27 Thread Rakesh.Bhat
Hi,
Check your code:



Kind regards,

Rakesh Bhat 
PrimeSourcing(tm) 
The Global IT Services  business from i-flex - "Add Value Reduce Risk"
www.iflexsolutions.com/services/services.asp
i-flex solutions limited - Bangalore
Phone : (080) 5759-6873
Email :  Rakesh.Bhat@ iflexsolutions.com


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 27, 2005 2:33 PM
To: user@struts.apache.org
Subject: ServletContext NullPointerException
Importance: Low

This is my code:

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.text.DateFormat;
import java.util.Date;

import app.Constants;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.sql.DataSource;
import java.sql.Connection; 
import java.sql.ResultSet; 
import java.sql.Statement; 
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.struts.action.Action;

public class MethodTest extends Action {
public void upisULogMetoda (HttpServletRequest request, 
HttpServletResponse response, String
statusUpisaLoga, String javaKlasa, 
String 
kategorijaUpisa, String sifraUpisa, String opis) 
throws ServletException, IOException
{
HttpSession session = request.getSession();

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try
{

ServletContext context = 
servlet.getServletContext();
DataSource dataSource = (DataSource)
context.getAttribute("org.apache.struts.action.DATA_SOURCE");
Connection conn2 = dataSource.getConnection(); <



stmt = conn.createStatement();  <--- it 
should be conn2 not conn.(I guess this is the reason )
String test = "INSERT INTO .";
stmt.executeUpdate(test);
stmt.close();

conn.commit();
conn.close();


}
catch(Exception e)
{
// ISKOCI I PRIKAZI PORUKU 
e.printStackTrace();
}   
finally
{
try { if (rs != null) rs.close(); } catch 
(SQLException ignoreThis) {}
try { if (stmt != null) stmt.close(); } catch 
(SQLException ignoreThis) {}
try { if (conn != null) conn.close(); } catch 
(SQLException ignoreThis) {}
}

}

}

In the line: ServletContext context = servlet.getServletContext();

i get NullPointerException. Why?

Tnx,
Stanislav

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]