Connect with us

News

How to use JavaScript in JSP

Published

on

How to use JavaScript in JSP

In this article, we will help all the Web Developers to get started with JavaScript and JavaServerPage.

Java Server page is often used at the development of server based applications. This server based application is no doubt very important in the modern webpage design and we also set standard security and validation process by JavaScript. So it is easy to say that JSP and JavaScript is interrelated with each other and thorough this way we can develop the page dynamically and process the pages. Java Script is the Microsoft implementation of the ECMA 262 language specification. Java Script is a language that is full implementation with some enhancements that take advantage of capabilities of Microsoft Internet Explorer.

Java Script is an object oriented event driven scripting language. This language is supports us communicating with various dynamic scripting languages. Java Script is no doubt very popular to server side developers. We know that modern world is running with online based systems. This online based system directly interacts with sever and also checking different types of event processing which we use regularly. So at first we have to know different event handling procedures of Java Script as well as the features of Java Script. As Java Script is very popular language so let us check why it is more important? Now discussing about Java Script!

Features of JavaScript

Following are some important features of JavaScript:

  • JavaScript is a Scripting Language.
  • JavaScript is lightweight.
  • JavaScript can be inserted into HTML pages and also call from the HTML pages.
  • JavaScript inserted into HTML pages can be executed by all modern web browsers like IE, FF, and Opera etc.
  • Java Script model can work easily with Java Server Page application model.

Java Server Page Alert is used to put the validation on login page for the users. The example in this Article provides to create the validation on the login form using JavaScript method in JSP (Java Server Page). The Article demonstrates an elaborative example to create alert box in a JSP page. Now we create a JSP file with name “validation.jsp”. The validation message surrounds the code for User Login page that include the ‘LoginName’ and ‘Password’. If we use to apply the validation we make use of JavaScript method in validation.jsp to validate the LoginName and password. Now here we set submit button in Java Server Page to call a JavaScript’s function validlogin (). The function validlogin () is used to validate the username and password in JSP (Java Server Page). Now if the username and password field is not inserted by the user then this will display mistake message using “alert ()”. The function also ensures that the field username and password must not be blank otherwise it will display only the message “Welcome mrbool readers “.

Listing 1: Showing sample validation

<html>
<head>
<script>
function validLogin() // java script function is created
{
if(document.frm1.userName.value == "")
{
alert ( "Please enter mrbool Login Name." ); //java script message will be display
document.loginform.userName.focus();
return false;
}
if (document.frm1.pass.value == "")
{
alert ( "Please Enter your secret password….." );
document.userform.password.focus();
return false;
}
alert("Welcome mrbool readers" );
return true;
}
</script>
</head>
<body>
<form name="frm1" method="post" onsubmit="return validLogin();">
<table width="150px" border=0 style="background-color: H0080FF80;">
<tr><td colspan=2 align="center" style="font-weight:bold;font-size:20pt;" align="center"><b>B.C.E.I User Login Form.</b></td>
</tr>
<tr><td colspan=2> </td>
</tr>
<tr><td style="font-size:12pt;" align="center">Enter login Name:</td>
<td><input type="text" name="userName" value=""></td>
</tr>
<tr><td style="font-size:12pt;" align="center">Enter Password:</td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login as B.C.E.I User’s"></td>
</tr>
</table>
</form>
</body>
</html>

We have deliberated the allocation about JSP. JSP is server side scripting language as we know but at this point it should be remembered that in real world programming we need more than JSP. Assume that we have an html (Hypertext markup language) form (Html form that contains only html tags in this page no JSP code is present) having username text field, and password field. As this is login id page so much more security should be present here. Before submitting the page to web server, it should be validate HTML (Hypertext markup language) field data. These types of validation can be done on client side instead of directly on server side. It should be done on client side, because it is very fast than server side validation process. If user data is not of specified range of standard validation program then it should be shown as an error at client browser of the user. This form will not jump to action page (server) until it is fully validated.

Listing 2: Sample showing form validation

<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<html>
<head>
<script>
function validateForm()
{
    if(document.frm.username.value=="")
    {
      alert("User Name should not be blank..");
      document.frm.username.focus();
      return false;
    }
    else if(document.frm.pwd.value=="")
    {
      alert("Password should not be blank");
      document.frm.pwd.focus();
      return false;
    }
}
</script>
</head>
<body>
<form name="frm" method="get" action="validity.jsp" onSubmit="return validateForm()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="22%"> </td>
    <td width="78%"> </td>
    </tr>
  <tr>
    <td>Enter UserName </td>
    <td><input type="text" name="username" /></td>
  </tr>
  <tr>
    <td>Enter Password</td>
    <td><input type="text" name="pwd" /></td>
  </tr>
  <tr>
    <td> </td>
    <td><input type="submit" name="submit" value="Submit"></td>
    </tr>
  <tr>
    <td> </td>
    <td> </td>
    </tr>
</table>
</form>
</body>
</html>

When we submit this form to web server, first it will check and validate the form. At the onSubmit=”return validateForm()” event check validateForm() function in javascript, and if any field is blank then it will throw an error alert on browser. This submit is successful only when validateForm() function returns true. Then goes to next form validateInput.jsp of JSP page.

This is an example implemented here to develop JSP code with JavaScript program model. The model program is a database related program. Here we create a database program and setup deletion operation and through this deletion operation user can delete the data. After deletion a message will be displayed using java script alert process. This way we can also print alert message for updating and insertion process.

Some point should be remembered that when we wish to print the document then this java script code helps us to develop this operation.

Listing 3: Sample showing database driven operation

<%@ page language="java" import="java.lang.*" import="java.sql.*" %>
<%
Connection con = null;
String url = "jdbc:mysql://127.0.0.1:3306/";	//my sql server IP 
String db = "cei"; // this is the database name
String driver = "com.mysql.jdbc.Driver"; //this is the driver name
String userName ="subrata"; //this is mysql user name
String password="srimani"; // this is mysql password
String str=request.getParameter("r1");
String sname=request.getParameter("sname");
String roll=request.getParameter("roll");
int stuID=Integer.parseInt(code);
try {
Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);
String sql = "delete from cei_student where roll= ?";
PreparedStatement stmt=null;
stmt=con.prepareStatement(sql);
stmt.setInt(1,stuId);
int del=stmt.executeUpdate();
if(del==0) { %>
<script language="javascript">
alert("Deletion successful");	//Java Script alert message
</script>
<%
}
if(del==1) { %>
<script language="javascript">
alert("Deletion successful");
</script>
<%
}
stmt.close();
con.close();
out.println("Data delete successfully from database…..");
}
catch(Exception e) {
out.println(e);
}
%>

Conclusion

It is clear as day light that the Java Server Page is working on most of the online based systems that are running through various security level procedure and this security is totally written in the phase of JavaScript model. This JavaScript model is compatible with Java Server Page program. We can set email check, numeric check, alphabet check in the program segment process. So JS is The Best Way to implement security based program on the JSP platform.

News

Business books to read in 2021: top picks

Published

on

By

Business books to read in 2021: top picks

The COVID pandemic has changed habits and reassigned priorities for all of us. There is, however, a segment of people whose natural way to treat crisis is to use the opportunities it offers: the entrepreneurs.

With an unprecedented economy stimulus coming from the U.S. Federal Reserve, the idea of starting new business (or investing in an existing one) became even more popular than previously. This, however, requires a certain level of preparation: you definitely don’t want to learn on your own mistakes losing money. Thankfully, business and entrepreneurship is the field where there are tons of useful and inspiring books to learn from.

But how to navigate through those thousands of books and authors? Let’s make an overview of the most in-demand business ebooks as of 2021.

Finance and Investments

Business books to read in 2021: top picks

Strongly recommended is “The Intelligent Investor” by Benjamin Graham, an eminent economist and investor of the 20th century. He has created a guide that has inspired millions of people around the world for 70 years. Since its first publication in 1949, the book has become a veritable bible of the stock market. The modern edition is supplemented by comments by financial journalist Jason Zweig, who draws parallels between Graham’s examples and modern realities, and also provides a deeper understanding of how to adapt the author’s philosophy to everyday life.

Internet Technology

The ITIL (Information Technology Infrastructure Library) is a framework for standardizing the selection, planning, provision, maintenance and the entire life cycle of IT services in a company. The goal is to improve efficiency and achieve predictable service delivery. 

The ITIL books cover key concepts of service management, the four dimensions of service management, the ITIL service value system, and ITIL management practices.

Entrepreneurship

This is an extremely wide field of study, incorporating both motivational, inspiring books with those designed to improve hard skills. As for the first option, the “Money: Master the Game” by Tony Robbins keeps first place in our wish list.

Another must-read is “Think and grow rich” by Napoleon Hill. This bestseller was written in the end of the 20th century and has been reprinted over 40 times. In his book, the author has collected the stories of famous millionaires of his time who stubbornly went towards their goals.

Continue Reading

News

What is The Full Form of PhD?

Published

on

By

The full form of PhD is a Doctor of Philosophy or a Doctorate in Philosophy.

This is a postgraduate academic degree awarded to individuals who have gone through the process of studying and researching extensive subject matter in their field. It can be obtained from an accredited university and requires one to go through a research dissertation.

What Is The Meaning Of PHD?

PhD is a doctoral degree that takes the form of a research degree. It generally recommends a substantial amount of independent, original research and a formal defence of that research.

The word “Doctor” in the abbreviation PhD comes from Latin “doctor” which means “teacher”. In other words, PhD holders are teachers who have done extensive teaching and research as demonstrated by their dissertation.

What Is The Abbreviation Of Doctorate of Philosophy?

PhD is the abbreviation for Doctorate of Philosophy.

Doctorate of Philosophy is a postgraduate degree that requires three to five years of study and research. The abbreviation for Doctorate of Philosophy is PhD.

Which is higher MD or PhD?

A person can be awarded with a Master of Science degree (MS) after completing course work and passing a series of written and oral exams. Master’s degrees typically take one to three years to complete.

A PhD is a Doctoral Degree, which is the highest academic award in most countries. To earn a PhD in the US, students usually have to complete at least four years of study beyond an undergraduate degree.

Master’s degrees are often seen as higher than Doctoral Degrees because they require more advanced subject knowledge and coursework.

Continue Reading

News

NEW from Apple

Published

on

By

We weren’t the only ones streaming the party yesterday. Apple held its latest event — the one that annually triggers iOS users to stop and think, “Hm, do I need an upgrade?”

Mobile gamers, in particular, could be tempted by the new iPhone 13 Pro and Pro Max, which got the new A15 Bionic chip. Apple said it’s the “fastest CPU in any smartphone” with a 6-core CPU (one more than the new non-Pro models). Because of the updates, the Pro models allow for 50% faster graphics and can last about 1.5-2.5 hours longer than the iPhone 12 Pro and Max models, respectively.

Apple unveiling a new iPhone with a better camera is a free space on your bingo card every year. With this update, Pro models got a bigger, 77 mm telephoto lens (these help you to take photos of subjects that are farther away) with night mode and 3x optical zoom (up from 2x-2.5x). Users also get new wide and ultrawide cameras, autofocus, and a new mode for taking close-ups up to 2cm away.

The standard iPhone 13 and Mini models also feature the A15 Bionic chip. The dual camera got updates as well, but Apple is mostly playing up its new Cinematic Mode across all models. It’s basically portrait mode but for video.

Apple Watch Series 7 also got some upgrades, most notably a wider screen and 20% larger display.

NEW from Apple

The biggest star of the show though was probably the iPad — specifically the new iPad Mini. It got the A15 Bionic chip and lost its home button — meaning it now looks like a mini iPad Air complete with a USB-C port and Touch ID on the power button. The iPad and iPad Mini also got ultrawide cameras with Center Stage. The feature uses machine learning to adjust the front-facing camera during FaceTime video calls to keep you in frame.

We’re looking forward to hearing what you’re most excited about and what you’re disappointed by — you too, Android users.

Continue Reading

Trending