Skip to main content

servelet&jsp

Servelet
&
JSP






Can use web.xml or Annotations to link form action to Servelet




<form method="post" action="Validate">
Name:<input type="text" name="user" /><br/>
Password:<input type="password" name="pass" ><br/>
<input type="submit" value="submit">
</form>

Welcome.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Welcome extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println("<h2>Welcome user</h2>");
 
    }
}
Validate.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Validate extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
      
            String name = request.getParameter("user");
            String password = request.getParameter("pass");

            if(password.equals("studytonight"))
            {
                RequestDispatcher rd = request.getRequestDispatcher("Welcome");
                rd.forward(request, response);
            }
            else
            {
                out.println("<font color='red'><b>You have entered incorrect password</b></font>");
                RequestDispatcher rd = request.getRequestDispatcher("index.html");
                
            }
  
    }
}



web.xml
<web-app>
    <servlet>
        <servlet-name>Validate</servlet-name>
        <servlet-class>Validate</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>Welcome</servlet-name>
        <servlet-class>Welcome</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Validate</servlet-name>
        <url-pattern>/Validate</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Welcome</servlet-name>
        <url-pattern>/Welcome</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        </welcome-file-list>
</web-app>

JSP

  • JSP technology is used to create dynamic web applications. JSP pages are easier to maintain then a Servlet. JSP pages are opposite of Servlets as a servlet adds HTML code inside Java code, while JSP adds Java code inside HTML using JSP tags. Everything a Servlet can do, a JSP page can also do it.


  • A JSP page looks similar to an HTML page, but a JSP page also has Java code in it. We can put any regular Java Code in a JSP file using a scriplet tag which start with <% and ends with %>. JSP pages are used to develop dynamic responses.

There are five different types of scripting elements

Scripting ElementExample
Comment<%-- comment --%>
Directive<%@ directive %>
Declaration<%! declarations %>
Scriptlet<% scriplets %>
Expression<%= expression %>
                                                                              JSTL
JSP Standard Tag Library(JSTL) is a standard library of readymade tags. The JSTL contains several tags that can remove scriplet code from a JSP page by providing some ready to use, already implemented common functionalities.
  • JSTL Core provides several core tags such as if, forEach, import, out etc to support some basic scripting task. Url to include JSTL Core Tag inside JSP page is →

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>




Comments

Popular posts from this blog

Oracle Fusion

  How to Create User and add roles in Fusion  with Basic Roles After adding roles run Retrieve Latest ldap changes is the process available in the Oracle cloud to sync User Account information's should be sync with the Oracle application from LDAP directory    :Retrieve Latest LDAP Changes process"    You can perform the task Run User and Roles Synchronization Process from either an implementation project or the Setup and Maintenance work area.

OIC

 

1& 2 - Introduction to Fusion Cloud and Course Content

  Front End Pages were developed using JET Framework. Backend access won't be available we have to use BI server FRS/Smart view - Essbase OTBI - Subject Area BIP - Select tables In Fusion Cloud applications you cannot create the process all together from the beginning and you cannot modify the the workflow process also so what you can do you can configure the approval rules you can configure the approval so that means who can approve who has to take the action who has to be notified so all those approval rules . If process is not there you cannot do anything