Avatar of princehyderabad
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
JSP

Avatar of undefined
Last Comment
jaggernat

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
suprapto45

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
suprapto45

I think that this is related to https://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21991629.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.
jaggernat

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.
jaggernat

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/Web/Web_Languages/JSP/Q_21991292.html

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck