File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP Alert Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Alert Box" Watch "JSP Alert Box" New topic
Author

JSP Alert Box

Pravin Venkatesh Venkatraman
Greenhorn

Joined: Oct 25, 2010
Posts: 2
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

Joined: Oct 21, 2010
Posts: 52
your code is correct please check with the browser settings


Thanks & Regards
Santosh Kumar.D

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Oct 21, 2010
Posts: 52
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Oct 21, 2010
Posts: 52
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Oct 21, 2010
Posts: 52
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Oct 21, 2010
Posts: 52
yes you are right,thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Alert Box