Write a JSP script to accept UserName and his NickName through html page and then displays username when visit count to page is odd and displays nickname when the visit count to the page is even. 

VisitPage.html

<html>
<body>
<form method=get action="VisitPage.jsp">
Enter User Name : <input type=text name=uname><br><br>
Enter Nick Name : <input type=text name=nname><br><br>
<input type=submit value="visit">
</form>
<body>
</html>

VisitPage.jsp

<html>
<body>
<%!
       int cnt=0;
       String uname,nname;
%>
<%
      uname=request.getParameter("uname");
       nname=request.getParameter("nname");
       cnt++;
      if(cnt%2==0)
       out.println("Hello "+nname+".........    Visit Count   "+cnt);
      else
       out.println("Hello "+uname+".........    Visit Count   "+cnt);
%>
<br><br>
<a href="VisitPage.html">VISIT</a>
</body>
</html>

Comments

Popular posts from this blog

Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a record in it.

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form. (Use PreparedStatement interface)