Wednesday, June 3, 2020

Jsp tutorial


JSP HELLO WORLD

Eclipse-->new -->Dynamic Web Project
---->webcontent--->jsp file

Program


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

out.println("hai");



%>



</body>
</html>

Run Program

right click-->run as--->run server--->apache tomact 7.0




Addition of two numbers using jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

int a,b,c;
a=10;
b=20;
c=a+b;
out.println("c is "+c);



%>



</body>
</html>


O/P

c is 30


Run time input

exam.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

Username <input type="text" name="n1"><br><br>
Password <input type="password" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>


exam1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

String a=request.getParameter("n1");
String b=request.getParameter("n2");

out.println(a);
out.println("<br>");
out.println(b);


%>




</body>
</html>


if-else

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

a <input type="text" name="n1"><br><br>
b <input type="text" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>

exam1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

int a,b;
a=Integer.parseInt(request.getParameter("n1"));
 b=Integer.parseInt(request.getParameter("n2"));
if(a>b)
{
out.println("a is big");
}

else
{
out.println("b is big");
}

%>




</body>
</html>

username and password checking

exam.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="exam1.jsp" method="post">

username <input type="text" name="n1"><br><br>
password<input type="password" name="n2"><br><br>

<input type="submit">

</form>


</body>
</html>

exam1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

String a,b;
a=request.getParameter("n1");
 b=request.getParameter("n2");
if(a.equals("admin") && b.equals("admin"))
{
out.println("correct password");
}

else
{
out.println("wrong password");
}

%>




</body>
</html>

No comments:

Post a Comment

Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...