Saturday, 2 December 2017

How to get session using java jsp programming code

Learning Java Programming Made Easy

get session using java jsp programming code 

Page 1:

/***********************************************//

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
   
    <body>
         
        <%
        String username=request.getParameter("username");
        //String password=request.getParameter("password");
        out.println("welcome : "+username);
      //  session.setAttribute("user",username);     
        %>
        <a href="sessionsecond.jsp?user=<%=username%>">gotonextpage</a>
    </body>
</html>

/**********************************************//


Page 2:

/**********************************************//
<%-- 
    Document   : sessionsecond
    Created on : Dec 7, 2016, 11:13:13 AM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            //String usermname=session.getAttribute("user").toString();
            String name=request.getParameter("user");
            String pass=request.getParameter("pass");
          out.println("Welcome : "+name);
        %>
        <a href="sessionthird.jsp">gotonextpage</a>
    </body>
</html>

/********************************************//


Page 3:

/***************************************//

<%-- 
    Document   : sessionstartpage
    Created on : Dec 7, 2016, 11:09:47 AM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="sessionfirstppag.jsp" method="post"> 
            <input type="text" name="username"><br/>
            <input type="text" name="password"><br/>
            <input type="submit" value="go">
        </form>
    </body>
</html>

/***************************************//

Page 4:

/****************************************//

<%-- 
    Document   : sessionthird
    Created on : Dec 7, 2016, 11:17:50 AM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
       <%
            //String usermname=session.getAttribute("user").toString();
            String usermname=request.getParameter("user");
          out.println("welcome : " +usermname);
        %>
    </body>
</html>


/******************************************//

How to include one jsp file into another jsp file body to display data java jsp programming code

Learning Java Programming Made Easy


Page 1: Hit Counter (jsp page)

/*******hits.jsp*******//
<%-- 
    Document   : hits
    Created on : Nov 30, 2016, 11:54:25 AM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<%
    Integer hitsCount = (Integer)application.getAttribute("hitCounter");
    if( hitsCount ==null || hitsCount == 0 ){
       out.println("first time!");
       hitsCount = 1;
    }else{
       /* return visit */
       out.println("Welcome back!");
       hitsCount += 1;
    }
    application.setAttribute("hitCounter", hitsCount);
%>
<p>Total number of visits: <%= hitsCount%></p>
</body>
</html>



/***********************************************************//


Page 2: (jsp file)


/************main.jsp**************/


<%-- 
    Document   : main
    Created on : Nov 30, 2016, 12:04:52 PM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<jsp:include page="hits.jsp" flush="true" />
</body>
</html>



How to use get and set property in java jsp programming

Learning Java Programming Made Easy



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<jsp:useBean id="test" class="action.testbean" />
<jsp:setProperty name="test" 
                    property="message" 
                    value="Hello JSP..." />
<jsp:getProperty name="test" property="message" />
</body>
</html>

how to use java program for website HIT Counter java jsp programming code

Learning Java Programming Made Easy






<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*" %>

<html>
<body>
<%
    Integer hitsCount = (Integer)application.getAttribute("hitCounter");
    if( hitsCount ==null || hitsCount == 0 ){
       out.println("first time!");
       hitsCount = 1;
    }else{
       /* return visit */
       out.println("Welcome back!");
       hitsCount += 1;
    }
    application.setAttribute("hitCounter", hitsCount);
%>
<p>Total number of visits: <%= hitsCount%></p>
</body>
</html>

How to use checkbox program in java jsp

Learning Java Programming Made Easy

Page 1:


<%-- 
    Document   : check
    Created on : Feb 9, 2017, 11:40:10 AM
    Author     : my pc
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
    <form action="checkcall.jsp" method="POST" target="_blank">
    <input type="checkbox" name="a" checked="checked" /> A
    <input type="checkbox" name="b"  /> B
    <input type="checkbox" name="c" checked="checked" /> C
<input type="submit" value="Select Subject" />
</form>
</body>
</html>



/************************************************************************/



Page 2:


<%-- 
    Document   : checkcall
    Created on : Feb 9, 2017, 11:40:30 AM
    Author     : my pc
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<b>A Flag:</b><%= request.getParameter("a")%>
<b>B Flag:</b><%= request.getParameter("b")%>
<b>C Flag:</b><%= request.getParameter("c")%>
</body>
</html>

How to send data from one page to other page java jsp programming code

Learning Java Programming Made Easy


Page 1: first page (html/jsp)



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <!--script let java code-->
        <%
            out.println("<h1>hello how are u</h1>");
        %>
        <br>
        <!--expression java code-->
        <%= "hi hello how are u"%>
        <br>
        <!--declaration java code-->
        <%! int age = 18;%>
        <%!

            int sum(int i, int j) {
                return i + j;
            }

        %>  
        <%= "the sum of 2 no=" + sum(4, 5)%><br>
        <%= "the age of emp=" + age%><br>
        <jsp:forward page="forwrod.jsp"></jsp:forward>
    </body>
</html>



Page 2: Second page (HTMl/JSP) 

<%-- 
    Document   : second
    Created on : Jan 31, 2017, 11:33:55 AM
    Author     : my pc
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

        <form action="third.jsp">
            username:<input type="text" name="user"/>
            <input type="submit" value="click"/>
        </form>
           
    </body>
</html>




Page 3: Third page (html/jsp)



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
      <%
      String str=request.getParameter("user");
      out.println("username="+str);
      %>
    </body>
</html>

How to get todays date using java jsp code and programming

Learning Java Programming Made Easy



<%-- 
    Document   : date
    Created on : Feb 14, 2017, 12:12:49 PM
    Author     : my pc
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html> 
<body>
<p>
   Today's date: <%= (new java.util.Date().toString())%>
</p>
</body> 
</html>

How to call stored COOKIES using java jsp programming code and get data out

Learning Java Programming Made Easy




<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<body>

    <form action="coock.jsp" method="GET">

First Name: <input type="text" name="first_name">

<br />
Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>

</body>



How to store COOKEIS using java jsp code

Learning Java Programming Made Easy



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
   // Create cookies for first and last names.      
   Cookie firstName = new Cookie("first_name",request.getParameter("first_name"));
   Cookie lastName = new Cookie("last_name",request.getParameter("last_name"));
   // Set expiry date after one hour for both the cookies.
   firstName.setMaxAge(1*1); 
   lastName.setMaxAge(1*1); 
   // Add both the cookies in the response header.
   response.addCookie( firstName );
   response.addCookie( lastName );
%>
<html>
<body>
<b>First Name:</b><%= request.getParameter("first_name")%><br/>
<b>Last  Name:</b><%= request.getParameter("last_name")%>
</body>
</html>

How to get IP using Java jsp programming

Learning Java Programming Made Easy




<%-- 
    Document   : ip
    Created on : Feb 14, 2017, 12:11:42 PM
    Author     : my pc
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
out.println("Your IP address is " + request.getRemoteAddr());
%>
</body>
</html>

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...