Monday, 8 April 2019

Validation Using JavaScript

Valid.html
_______________________

<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script type="text/javascript">

function validate() {
var username=document.getElementById('uname');
var password=document.getElementById('password');

if (username.value.trim()=="")
{

document.getElementById('lbuser').style.visibility="visible";
uname.style.border="solid 3px red";
return false;
}else if (password.value.trim()=="")
{
alert("please enter password");
return false;
     
}else if (password.value.trim().length<5)
{
alert("password lenght should be 5 ");
return false;
}else
{
return true;
}

}

</script>

</head>
<body>

<form onsubmit="return validate()" action="message.html">
<input type="text" id="uname" placeholder="username">
<label id="lbuser" style="color: red; visibility: hidden;">Please enter username</label>
</br></br>
<input type="password" id="password" placeholder="password"></br></br>
<button type="submit">submit</button>
</form>

</body>
</html>


Wednesday, 3 April 2019

CSS Programs inline,Internal,external

Inline:


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p style="color: green">The Republic Day is a national holiday of India, celebrated every year on 26th January.

This day celebrates the anniversary of the Constitution of India and the transition of India from a British Dominion to a republic on 26th January, 1950.

After getting freedom from the British rule on 15th August 1947, India was headed by King George VI till the constitution of India came into force on 26th January 1950. On this day India is declared as a democratic republic nation. Dr. Rajendra Prasad was elected as the first president of India.</p>

</body>
</html>

________________________________________________________________________________

Internal :

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
p{
color: brown;
}
</style>


</head>
<body>
<p>The Republic Day is a national holiday of India, celebrated every year on 26th January.

This day celebrates the anniversary of the Constitution of India and the transition of India from a British Dominion to a republic on 26th January, 1950.

After getting freedom from the British rule on 15th August 1947, India was headed by King George VI till the constitution of India came into force on 26th January 1950. On this day India is declared as a democratic republic nation. Dr. Rajendra Prasad was elected as the first president of India.</p>

</body>
</html>

______________________________________________________________________________


External:

makeup.css

p{
color: red;

}


<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="makeup.css">
</head>
<body>
<p>The Republic Day is a national holiday of India, celebrated every year on 26th January.

This day celebrates the anniversary of the Constitution of India and the transition of India from a British Dominion to a republic on 26th January, 1950.

After getting freedom from the British rule on 15th August 1947, India was headed by King George VI till the constitution of India came into force on 26th January 1950. On this day India is declared as a democratic republic nation. Dr. Rajendra Prasad was elected as the first president of India.</p>

</body>
</html>

Java Script Programs

bulb on off:
----------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<img id="imgs" src="off.png"><br>
<button onclick="document.getElementById('imgs').src='on.png'">Switch On
</button>
<button onclick="document.getElementById('imgs').src='off.png'">Switch off

</button>

</body>
</html>

______________________________________________________________________

TextBlast disappear :

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p2">WELCOME To AVANTHI CSE</p>
<button onclick="document.getElementById('p2').style.display='none'">Blast</button>


</body>
</html>
_________________________________________________________________________


Current Date:

<!DOCTYPE html><html>
<head>
<title></title>
</head>
<body>
<p id="p2">Date is</p>
<button onclick="document.getElementById('p2').innerHTML=Date()">Date</button>

</body>
</html>

_____________________________________________________________________________

buttons onlick :

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p1">This is UK Language</p>
<button onclick="document.getElementById('p1').innerHTML='This is Australia Language'">Australia</button>
<button onclick="document.getElementById('p1').innerHTML='This is China Language'">China</button>
<button onclick="document.getElementById('p1').innerHTML='This is Japan Language'">Japan</button>
<button onclick="document.getElementById('p1').innerHTML='This is Canada Language'">Canada</button>


</body>
</html>

____________________________________________________________________________

change Font:


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p2">Mohandas Karamchand Gandhi, who was also known as Mahatma, "Great Soul" Gandhi, was a hero, as well as a political and spiritual leader of India. He was of the Hindu faith, of which I am too. Mohandas brought India to independence by using non-violent resistance. He thought that there was injustice being served to the Indians, especially to the immigrants by the South Africans. Gandhi was born on October 2, 1869 in Porbandar, Kathiawar, now known as Gujarat. Gandhi passed away at the age of 78 on January 30, 1948. Mahatma Gandhi was brought up in India near Rajkot, where he did most of his studies. In 1888, Gandhi went to London, leaving his wife and son behind, to pursue his degree in law. Later in 1893, Gandhi went to South Africa to work and found that there was a lot of prejudice towards Indians. That was the reason Gandhi began protesting and eventually he became an inspiring hero for millions. The three main qualities that define Gandhi as a hero are his strong leadership, simplicity and bravery.</p>
<button onclick="document.getElementById('p2').style.fontFamily='Ravie'">
change me
</button>

</body>
</html>

________________________________________________________________________________

change Size:


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p3">It’s our unshakeable belief that India will never achieve its true growth story until the rural sector of the country is empowered to make choices and transform their own lives. With this thought, we initiated SHARE (Society to Heal Aid Restore Educate) in 1983. In 2013, SHARE metamorphosed into the Swades Foundation with a mission to empower rural lives through a unique 360-degree development model which covers four key thematic areas namely Health & Nutrition, Education, Water & Sanitation and Economic Development. Our aim is to ensure that this model can be replicated at scale across India and perhaps even the world.
</p>
<button onclick="document.getElementById('p3').style.fontSize='32px'">change Size</button>

</body>
</html>

_________________________________________________________________________________

variable declaration:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var a=10;
document.writeln(a);


</script>

</body>
</html>

_________________________________________________________________________________

variable add:



<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p1"></p>
<script type="text/javascript">
var a=10;
var b=20;
var c;
c=a+b;
document.getElementById('p1').innerHTML=c;

</script>

</body>

</html>

________________________________________________________________________________

undefine:


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p5"></p>
<script type="text/javascript">
var a;
document.getElementById('p5').innerHTML=a;
</script>
</body>
</html>
________________________________________________________________________________

stringadd:


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p2"></p>
<script type="text/javascript">
var a="vanja";
var b="manasa";
var c;
c=a+b;
document.getElementById('p2').innerHTML=c;


</script>

</body>
</html>

______________________________________________________________________________

StringVarAdd:



<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p4"></p>
<script type="text/javascript">
var a=10;
var b="manasa";
var c;
c=a+b;
document.getElementById('p4').innerHTML=c;
</script>

</body>
</html>

________________________________________________________________________________

StringVarAdd2:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p4"></p>
<script type="text/javascript">
var a=10;
var b="manasa";
var d=10;
var c;
c=b+a+d;
document.getElementById('p4').innerHTML=c;
</script>

</body>
</html>
_____________________________________________________________________________

StringVarAdd3:


<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p4"></p>
<script type="text/javascript">
var a=10;
var b="manasa";
var d=10;
var c;
c=a+d+b;
document.getElementById('p4').innerHTML=c;
</script>

</body>
</html>

_____________________________________________________________________________

Array:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p2">HELLO</p>
<script type="text/javascript">
var names=["Ramesh","Suresh"];
document.getElementById('p2').innerHTML=names[0]+"<br>"+names[1];
</script>

</body>
</html>

____________________________________________________________________________

ArrayMultiLevel:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="p6"></p>
<script type="text/javascript">
var names={ Firstname : "manasa",
                    Lastname : "vanja",
                    Age : 20,
                    Education : "b.tech"
                };
   document.writeln(names.Firstname,names.Lastname,names.Age,names.Education);
</script>

</body>
</html>
_____________________________________________________________________________



Wednesday, 27 March 2019

Real Time Login App using session

  1. index.html
  2. link.html
  3. login.html
  4. LoginServlet.java
  5. LogoutServlet.java
  6. ProfileServlet.java
  7. web.xml
index.html 

<!DOCTYPE html>  
<html>  
<head>  
<meta charset="ISO-8859-1">  
<title>Servlet Login Example</title>  
</head>  
<body>  
  
<h1>Welcome to Login App by Cookie</h1>  
<a href="login.html">Login</a>|  
<a href="LogoutServlet">Logout</a>|  
<a href="ProfileServlet">Profile</a>  
  
</body>  
</html>  


servlet cookie login example 1


link.html


  1. <a href="login.html">Login</a> |  
  2. <a href="LogoutServlet">Logout</a> |  
  3. <a href="ProfileServlet">Profile</a>  
  4. <hr>




servlet cookie login example 2

Login.html

  1. <form action="LoginServlet" method="post">  
  2. Name:<input type="text" name="name"><br>  
  3. Password:<input type="password" name="password"><br>  
  4. <input type="submit" value="login">  
  5. </form>  


LoginServlet.java


  1. import java.io.IOException;  
  2. import java.io.PrintWriter;  
  3. import javax.servlet.ServletException;  
  4. import javax.servlet.http.Cookie;  
  5. import javax.servlet.http.HttpServlet;  
  6. import javax.servlet.http.HttpServletRequest;  
  7. import javax.servlet.http.HttpServletResponse;  
  8. public class LoginServlet extends HttpServlet {  
  9.     protected void doPost(HttpServletRequest request, HttpServletResponse response)  
  10.                            throws ServletException, IOException {  
  11.         response.setContentType("text/html");  
  12.         PrintWriter out=response.getWriter();  
  13.           
  14.         request.getRequestDispatcher("link.html").include(request, response);  
  15.           
  16.         String name=request.getParameter("name");  
  17.         String password=request.getParameter("password");  
  18.           
  19.         if(password.equals("admin123")){  
  20.             out.print("You are successfully logged in!");  
  21.             out.print("<br>Welcome, "+name);  
  22.               
  23.            // Cookie ck=new Cookie("name",name);  
  24.           //  response.addCookie(ck);  

  1.          HttpSession session=request.getSession();  
  2.         session.setAttribute("name",name); 

  1.         }else{  
  2.             out.print("sorry, username or password error!");  
  3.             request.getRequestDispatcher("login.html").include(request, response);  
  4.         }  
  5.           
  6.         out.close();  
  7.     }  
  8.   
  9. }  

servlet cookie login example 4



servlet cookie login example 3




 LogoutServlet.java



  1. import java.io.IOException;  
  2. import java.io.PrintWriter;  
  3. import javax.servlet.ServletException;  
  4. import javax.servlet.http.Cookie;  
  5. import javax.servlet.http.HttpServlet;  
  6. import javax.servlet.http.HttpServletRequest;  
  7. import javax.servlet.http.HttpServletResponse;  
  8. public class LogoutServlet extends HttpServlet {  
  9.     protected void doGet(HttpServletRequest request, HttpServletResponse response)  
  10.                         throws ServletException, IOException {  
  11.         response.setContentType("text/html");  
  12.         PrintWriter out=response.getWriter();  
  13.           
  14.           
  15.         request.getRequestDispatcher("link.html").include(request, response);  
  16.           
  17.        // Cookie ck=new Cookie("name","");  
  18.     //    ck.setMaxAge(0);  
  19.      //   response.addCookie(ck);  


  1.  HttpSession session=request.getSession();  
  2.             session.invalidate();  
  1.           
  2.         out.print("you are successfully logged out!");  
  3.     }  
  4. }  
servlet cookie login example 6


ProfileServlet.java

  1. import java.io.IOException;  
  2. import java.io.PrintWriter;  
  3. import javax.servlet.ServletException;  
  4. import javax.servlet.http.Cookie;  
  5. import javax.servlet.http.HttpServlet;  
  6. import javax.servlet.http.HttpServletRequest;  
  7. import javax.servlet.http.HttpServletResponse;  
  8. public class ProfileServlet extends HttpServlet {  
  9.     protected void doGet(HttpServletRequest request, HttpServletResponse response)  
  10.                           throws ServletException, IOException {  
  11.         response.setContentType("text/html");  
  12.         PrintWriter out=response.getWriter();  
  13.           
  14.         request.getRequestDispatcher("link.html").include(request, response);  
  15.           
  16.      //   Cookie ck[]=request.getCookies();  
  17.      //   if(ck!=null){  
  18.      //    String name=ck[0].getValue();  
  19.     //    if(!name.equals("")||name!=null){  
  20.       //      out.print("<b>Welcome to Profile</b>");  
  21.     //        out.print("<br>Welcome, "+name);  
  22.     
  23.       HttpSession session=request.getSession();  
  24.         if(session!=null){  
  25.         String name=(String)session.getAttribute("name");
  26.         out.print("Hello, "+name+" Welcome to Profile");  
  27.   }  

  28.         }else{  
  29.             out.print("Please login first");  
  30.             request.getRequestDispatcher("login.html").include(request, response);  
  31.         }  
  32.         out.close();  
  33.     }  
  34. }  
servlet cookie login example 5


Web.xml


  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3. xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
  4. http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  
  5.     
  6.   <servlet>  
  7.     <description></description>  
  8.     <display-name>LoginServlet</display-name>  
  9.     <servlet-name>LoginServlet</servlet-name>  
  10.     <servlet-class>LoginServlet</servlet-class>  
  11.   </servlet>  
  12.   <servlet-mapping>  
  13.     <servlet-name>LoginServlet</servlet-name>  
  14.     <url-pattern>/LoginServlet</url-pattern>  
  15.   </servlet-mapping>  
  16.   <servlet>  
  17.     <description></description>  
  18.     <display-name>ProfileServlet</display-name>  
  19.     <servlet-name>ProfileServlet</servlet-name>  
  20.     <servlet-class>ProfileServlet</servlet-class>  
  21.   </servlet>  
  22.   <servlet-mapping>  
  23.     <servlet-name>ProfileServlet</servlet-name>  
  24.     <url-pattern>/ProfileServlet</url-pattern>  
  25.   </servlet-mapping>  
  26.   <servlet>  
  27.     <description></description>  
  28.     <display-name>LogoutServlet</display-name>  
  29.     <servlet-name>LogoutServlet</servlet-name>  
  30.     <servlet-class>LogoutServlet</servlet-class>  
  31.   </servlet>  
  32.   <servlet-mapping>  
  33.     <servlet-name>LogoutServlet</servlet-name>  
  34.     <url-pattern>/LogoutServlet</url-pattern>  
  35.   </servlet-mapping>  
  36. </web-app>