princehyderabad
asked on
JSP causing JS to error
hi,
Just a wired error: NullPointerException
JSP page:
...
//javascript
...
function main()
{
...
okay();
...
}
function okay()
{
<% System.out.print("........ ........") ; %>
alert("hi");
return true;
}
Works fine. But when I add this code it shows me error:
function okay()
{
<% System.out.print("........ ........") ;
// Calling Stored Procedure
CallableStatement cs2 = conn.prepareCall("{call abc(?) }");
cs2.setString(1, userID);
cs2.execute();
%>
return true;
}
PS: All variable is define and I'm getting all valid values
thx,
PH
Just a wired error: NullPointerException
JSP page:
...
//javascript
...
function main()
{
...
okay();
...
}
function okay()
{
<% System.out.print("........
alert("hi");
return true;
}
Works fine. But when I add this code it shows me error:
function okay()
{
<% System.out.print("........
// Calling Stored Procedure
CallableStatement cs2 = conn.prepareCall("{call abc(?) }");
cs2.setString(1, userID);
cs2.execute();
%>
return true;
}
PS: All variable is define and I'm getting all valid values
thx,
PH
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
first of all, trying to access database values using a scriplet from javascript code is a very bad idea.
javascript should be exclusively used for front-end operations and NOT backend. all your java code including database connectivity should be in a java class and when you submit your jsp, you make a call to that java class and perform all the databse operations in it.
javascript should be exclusively used for front-end operations and NOT backend. all your java code including database connectivity should be in a java class and when you submit your jsp, you make a call to that java class and perform all the databse operations in it.
Null pointer means it is returning empty or it does not have any thing in it and that is why you are getting that error
you had a very similar problem here.
https://www.experts-exchange.com/questions/21991292/NullPointerException.html
you had a very similar problem here.
https://www.experts-exchange.com/questions/21991292/NullPointerException.html
If you use
..
<%@ page import = "com.abc.Utils" %>
..
Connection conn = null;
Make sure that you have set the conn from the Utils class that you used.