Posts

Showing posts from November 29, 2016

JSP Example to create custom tag that will append a String to its own body and will display the result

JSP Example   to create custom tag that will append a String to its own body and will display the result Details.java package beginnersbook . com ; import javax . servlet . jsp . tagext .*; import javax . servlet . jsp .*; import java . io .*; public class Details extends SimpleTagSupport {    //StringWriter object    StringWriter sw = new StringWriter ();      public void doTag () throws JspException , IOException    {        getJspBody (). invoke ( sw );        JspWriter out = getJspContext (). getOut ();        out . println ( sw . toString ()+ "Appended Custom Tag Message" );    } } TLD file:   message.tld Remember to have this file in WEB-INF folder. <taglib> <tlib-version> 1.0 </tlib-version> <jsp-version> 2.0 </jsp-version> <short-name> My Custom Tag: MyMsg </short-name> <tag> <name> MyMsg </name> <tag-class> beginnersbook.com.Details </tag-class>

JSP Example to fetch Value using param variable of expression language

JSP Example  to fetch Value  using param variable of expression language  index.jsp <html> <head> <title> Expression language example2 </title> </head> <body> <form action = "display.jsp" > Student Name: <input type = "text" name = "stuname" /><br> Student RollNum: <input type = "text" name = "rollno" /><br> <input type = "submit" value = "Submit Details!!" /> </form> </body> </html> display.jsp <html> <head> <title> Display Page </title> </head> <body> Student name is ${ param.stuname } <br> Student Roll No is ${ param.rollno } </body> </html>

JSP Example for Exception implicit Object

JSP Example  for Exception implicit Object  index.html <html> <head> <title> Enter two Integers for Division </title> </head> <body> <form action = "division.jsp" > Input First Integer: <input type = "text" name = "firstnum" /> Input Second Integer: <input type = "text" name = "secondnum" /> <input type = "submit" value = "Get Results" /> </form> </body> </html> division.jsp <%@ page errorPage = "exception.jsp" %> <% String num1 = request . getParameter ( "firstnum" ); String num2 = request . getParameter ( "secondnum" ); int v1 = Integer . parseInt ( num1 ); int v2 = Integer . parseInt ( num2 ); int res = v1 / v2 ; out . print ( "Output is: " + res ); %> exception.jsp <%@ page isErrorPage = "true" %> Got this Ex

JSP Example for Session Implicit Object

Image
JSP Example  for Session Implicit Object  index.html <html> <head> <title> Welcome Page: Enter your name </title> </head> <body> <form action = "session.jsp" > <input type = "text" name = "inputname" > <input type = "submit" value = "click here!!" ><br/> </form> </body> </html> The   session.jsp   page displays the name which user has entered on the index page and it stores the same variable in the   session object   so that it can be fetched on any page until the session becomes inactive. session.jsp <html> <head> <title> Passing the input value to a session variable </title> </head> <body> <% String uname = request . getParameter ( "inputname" ); out . print ( "Welcome " + uname ); session . setAttribute ( "sessname" , uname ); %> <a

JSP Example for Request Implicit Object

JSP Example  for Request Implicit Object   . index.html <html> <head> <title> Enter UserName and Password </title> </head> <body> <form action = "userinfo.jsp" > Enter User Name: <input type = "text" name = "uname" /> <br><br> Enter Password: <input type = "text" name = "pass" /> <br><br> <input type = "submit" value = "Submit Details" /> </form> </body> </html> userinfo.jsp <%@ page import = " java.util.* " %> <html> <body> <% String username = request . getParameter ( "uname" ); String password = request . getParameter ( "pass" ); out . print ( "Name: " + username + " Password: " + password ); %> </body> </html>