This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Alert Box

 
Pravin Venkatesh Venkatraman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a newbie into jsp.
This code is not giving message box on exception.

try
{
String s8 = "localhost:1521:XE";
String s10 ="system";
String s11 ="system";
DriverManager.registerDriver(new OracleDriver());
Connection connection = DriverManager.getConnection("jdbcracle:thin:@" + s8, s10, s11);
Statement statement = connection.createStatement();
statement.executeUpdate("INSERT INTO TRAN_BILL_MASTER VALUES("+lv_billnum+","+lv_empnum+",(select cat_number from cat_master where cat_description='"+lv_catno+"'),'"+lv_ddmmyyyy+"','"+lv_mmmyy+"',(select cat_percentage from cat_master where cat_description='"+lv_catno+"'),"+lv_billamt+")");
}

catch(SQLException sqle)
{
%>
<script type="text/javascript">
alert("Check Input");
</script>
<%

//response.sendRedirect("http://localhost:8080/coop/bill_add.jsp");

}
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your code is correct please check with the browser settings

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
santosh dhulipala wrote:your code is correct please check with the browser settings

The code is far from correct.

You cannot mix JSP and JavaScript in this way. Java code in the page (discredited now for over 8 years -- you should update your JSP knowledge) executes on the server long before the page gets sent to the browser where JavaScript can execute.

Please read this article to understand how JSP operates.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pravin Venkatesh Venkatraman wrote:I'm a newbie into jsp.

If you are new to JSP, it's important that you get started on the right foot. As I mentioned in my previous reply, putting Java code into a JSP is an old-fashioned, discredited practice that should be avoided at all costs. Please update your JSP learning materials with those that use modern mechanisms like the JSTL and EL in place of antiquated Java scriptlets.
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Bear Bibeault,
we follow the standards for developing applications, i was just trying to say that what ever code he has written is correct and it should generate out put.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
santosh dhulipala wrote:thank you Bear Bibeault,
we follow the standards for developing applications, i was just trying to say that what ever code he has written is correct and it should generate out put.

No. The code is not correct. And it will not generate the expected output.

It has nothing to do with standards. It has to do with understanding JSP.
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The code is not correct. And it will not generate the expected output.

It has nothing to do with standards. It has to do with understanding JSP

ok, thank you for your sugesstion i am going through the articles you refered and will try to understand it very well.
i will reach you if i am not clear in any aspect
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To help you, answer this question: if an exception occurs, where will it be thrown and caught? The server or the browser?
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:To help you, answer this question: if an exception occurs, where will it be thrown and caught? The server or the browser?

please help me if i am wrong..

exceptions are raised when there are
1)Mistakes in coding
2)Situatons where client inputs are not according to the Standards we followed at the time of developing
and more

the user inputs from the clients side and the server process the data and the exceptions are raised at the server side which are caught by the controllers and the respective out put is generated to the client

hope i am correct and would get your help



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so if the exception is thrown and caught on the server, how can it execute JavaScript that hasn't even been sent to the browser yet?

The article points out that the JSP executes on the server to create an HTML page that is sent to the browser. Any JavaScript on the page is just template text that becomes part of the HTML to be sent to the browser.
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you are right,thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic