This Presentation shows the working of Java RMI technology, it's advantage over RPC, it's class hierarchy API and finally implementation of Factorial program using Java RMI.
Introduction to java beans, java beans, Core java, j2se, getting started with java beans programming, java to standard edition, beans in java, beans programming in java
This Presentation shows the working of Java RMI technology, it's advantage over RPC, it's class hierarchy API and finally implementation of Factorial program using Java RMI.
Introduction to java beans, java beans, Core java, j2se, getting started with java beans programming, java to standard edition, beans in java, beans programming in java
Overview of EJB technology.
Enterprise Java Beans (EJB) is a server-side component technology for Java EE based systems (JEE).
Beans are business logic components that implement a standard interface through which the bean is hooked into the bean container (= runtime object for bean).
A Java class implementing one of the standard bean interfaces is an Enterprise Java Bean. Beans can be accessed remotely, usually from a client tier.
The EJB standard was developed to provide a common framework for solving recurring problems in business application development like persistence, transactions,
security and runtime and lifecycle management. The EJB standard evolved greatly over time. EJB version 1 and 2 were complex and required to implement many interfaces
and exception handling in EJBs. EJB version 3 brought great simplifications and did away with interfaces by replacing these with annotations which provide greater flexibility while keeping complexity low. EJBs come in 3 different flavors: Stateless and stateful session beans and message driven beans. Entity beans of EJB version 1 and 2 were replaced by the Java Persistence API in EJB version 3.
Overview of EJB technology.
Enterprise Java Beans (EJB) is a server-side component technology for Java EE based systems (JEE).
Beans are business logic components that implement a standard interface through which the bean is hooked into the bean container (= runtime object for bean).
A Java class implementing one of the standard bean interfaces is an Enterprise Java Bean. Beans can be accessed remotely, usually from a client tier.
The EJB standard was developed to provide a common framework for solving recurring problems in business application development like persistence, transactions,
security and runtime and lifecycle management. The EJB standard evolved greatly over time. EJB version 1 and 2 were complex and required to implement many interfaces
and exception handling in EJBs. EJB version 3 brought great simplifications and did away with interfaces by replacing these with annotations which provide greater flexibility while keeping complexity low. EJBs come in 3 different flavors: Stateless and stateful session beans and message driven beans. Entity beans of EJB version 1 and 2 were replaced by the Java Persistence API in EJB version 3.
Протокол № 16-15ок заседания Комиссии по вопросам градостроительства, землепо...Дарья Каштанова
Протокол № 16-15ок заседания Комиссии по вопросам градостроительства, землепользования и застройки при Правительстве Москвы в Северо-Западном административном округе города Москвы
Presentation to President Obama's Science & Technology advisory council (PCAST) on STEM Education. See http://cacm.acm.org/blogs/blog-cacm/109290-our-big-idea-open-social-learning/
How can we rely upon Social Network Measures? Agent-base modelling as the nex...Bruce Edmonds
All social network analysis of observed systems rely on assumptions, for example: how a link is defined is the right one, how the resulting network is analysed actually corresponds with our conclusions about it, etc. In other words the representation+analysis is a *model* of what we observe. Any model is fallible and thus needs independent validation, but this is rarely done in social network analysis due to the cost. Indeed, the only check is often that of face validity by the same person who collected the data and analysed it!
This lack of established validity is somewhat hidden by the divide within the field of social networks between the "formalists" who prove abstract properties of networks and those who apply its techniques to observed cases (who I will call "practioners"). The formalists might propose SN measures and prove their properties, but do not say anything about their applicability to any observed system. The practioners often proceed as if the measures will "work" on their networks - e.g. that a measure of centrality will tend to highlight the most influential actors.
However, agent-based models (ABM) might offer a potential solution to this. If a measure (or other SN technique) does not work with a plausible ABM of the phenomena (where we can actually check this), then we certainly can not rely on it for a similar model of observed phenomena. Some results and examples of this are given. Rather, it might be that SNA might be more reliable as a secondary analysis -- a model of a complex ABM of observed phenomena.
An invited talk given at the Institute for Research into Superdiversity (IRIS), University of Brimingham, 31st Jan 2017
Abstract:
A simulation to illustrate how the complex patterns of cultural and genetic signals might combine to define what we mean by "groups" of people is presented. In this model both (a) how each individual might define their "in group" and (b) how each individual behaves to others in 'in' or 'out' groups can evolve over time. Thus groups are not something that is precisely defined but is something that emerges in the simulation. The point is to illustrate the power of simulation techniques to explore such processes in a non-prescriptive way that takes the micro-macro distinction seriously and represents them within complex simulations. In the particular simulation presented, groups defined by culture strongly emerge as dominant and ethnically defined groups only occur when they are also culturally defined.
In this slide share you can see Peter Opsvik's Philosophy of sitting. It features some amazing creative designs showing us how these unique designs can help us stay comfy. If you would like anymore information or want to enquire about one of the products featured in this slideshare please don't hesitate to contact us at info@ergomonkey.com
State management refers to the management of the state of one or more user interface controls such as text fields, OK buttons, radio buttons, etc. in a graphical user interface. In this user interface programming technique, the state of one User Interface control depends on the state of other User Interface controls.
CyberLab Training Division :
ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites. It allows you to use a full featured programming language such as C# or VB.NET to build web applications easily.
This tutorial covers all the basic elements of ASP.NET that a beginner would require to get started.
Audience
This tutorial has been prepared for the beginners to help them understand basic ASP.NET programming. After completing this tutorial you will find yourself at a moderate level of expertise in ASP.NET programming from where you can take yourself to next levels.
Prerequisites
Before proceeding with this tutorial, you should have a basic understanding of .NET programming language. As we are going to develop web-based applications using ASP.NET web application framework, it will be good if you have an understanding of other web technologies such as HTML, CSS, AJAX. etc
ASP.NET supports three different development models:
Web Pages, MVC (Model View Controller), and Web Forms.
For More Details.
Visit: http://www.cyberlabzone.com
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...SOFTTECHHUB
The choice of an operating system plays a pivotal role in shaping our computing experience. For decades, Microsoft's Windows has dominated the market, offering a familiar and widely adopted platform for personal and professional use. However, as technological advancements continue to push the boundaries of innovation, alternative operating systems have emerged, challenging the status quo and offering users a fresh perspective on computing.
One such alternative that has garnered significant attention and acclaim is Nitrux Linux 3.5.0, a sleek, powerful, and user-friendly Linux distribution that promises to redefine the way we interact with our devices. With its focus on performance, security, and customization, Nitrux Linux presents a compelling case for those seeking to break free from the constraints of proprietary software and embrace the freedom and flexibility of open-source computing.
Threats to mobile devices are more prevalent and increasing in scope and complexity. Users of mobile devices desire to take full advantage of the features
available on those devices, but many of the features provide convenience and capability but sacrifice security. This best practices guide outlines steps the users can take to better protect personal devices and information.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024Neo4j
Neha Bajwa, Vice President of Product Marketing, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
State management servlet
1. State management
Http protocol that is used for communication between client and web server
is a stateless protocol that is for each request new HTTP connection is
established between client and server.
The disadvantage of stateless protocol is that server fails to recognize that a
series of request submitted by a user or logically related and represent a
single task form end user prospective.
Problem of state management deals with the maintenance of state over
the stateless protocol.
Following use case explains the problem of state management:
2. Example 1- program ServletContext object is used for state management.
Program save with Name: index.html
<html>
<head><title>Inter Application Forwarding..</title></head>
<body>
<form method="get" action="welcomeServlet">
Name :<input type="text" name="txtName"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Program save with Name: WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String name=request.getParameter("txtName");
PrintWriter out=response.getWriter();
out.println("<b> Welcome, "+name+"</b>");
ServletConfig cnf=getServletConfig();
ServletContext ctx=cnf.getServletContext();
ctx.setAttribute("user",name);
out.println("<br> <form action=tourServlet method=get>");
3. out.println("<br><input type=submit value="Take a Tour "></form>" );
out.close();
}
}
Program save with Name: TourServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TourServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
ServletConfig cnf=getServletConfig();
ServletContext ctx=cnf.getServletContext();
String name=(String)ctx.getAttribute("user");
PrintWriter out=response.getWriter();
out.println("<b> Sorry, "+name+"</b>");
out.println("<br>Site is down for routine maintenance, vist again later..");
out.close();
}
}
Program save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>welcomeServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>TourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>tourServlet</url-pattern>
</servlet-mapping>
</web-app>
4. Output :
Run program on two browser and test with both users one by one
Yes This is not complete solution of state management so there is requirement of another
technique.
Problem with ServletContext object when we use it for state management:
Name of user is user specific which must not be store in ServletContext because other user
is override it.
Note: In ServletContext store only application specific data not store user specific data.
Following solution is device to solve the problem of State
management:
1- Cookies
2- Hidden form fields
3- URL rewriting
4- HttpSession object
1- Cookies
A cookie represent information in the form of key value pair which is send by the
server as part of response and is submitted by the browser to the server as part of
the sub sequent request.
Cookie provides a simple mechanism of maintaining user information between
multiple requests.
Cookie can be of 2 types:
1- Persistent cookies
2- Non Persistent cookies
1- Persistent cookies:
5. Persistent cookies remain valid for multiple sessions.
They are store by the browser in a text file on the client machine to be use
again and again.
2- Non Persistent cookies:
Non persistence cookies remain valid only for a
single session, they are store in the browser cache during the session and
discarded by the browser when the session is complete.
Note: By default all cookies are non persistent.
Advantage:
1- Simplicity is main advantage of this approach.
Disadvantage:
1- This method of state maintenance is browser dependent.
2- Only textual information can be persisted between request (Object Map,
File are not persisted in cookies).
3- Persistent cookies do not differentiate users on the machine.
Note: Netscape first introduce cookies.
javax.servlet.http.Cookie, class provides object representation of cookies.
Cookies object can be created using following constructor:
public Cookie(String name, String value);
6. Method of Cookie class:
1- getName():
Is use to obtain the name of the cookie.
public String getName();
2- getValue():
Is use to obtain the value of the cookie.
public String getValue();
3- setMaxAge():
Is use to specify the time for which cookie remain valid.
This method makes cookies persistent.
public void setMaxAge(int seconds);
etc…
addCookie():
Method of HttpServletResponse interface is used to add
the cookie as a part of the response.
public void addCookie(Cookie ck);
getCookies():
Method of HttpServletRequest interface is used to
obtain the cookies which are submitted as part of the request.
public Cookie[] getCookies();
Example 1- program for state management using Cookies.
Program save with Name: index.html
<html>
<head><title>Inter Application Forwarding..</title></head>
<body>
<form method="get" action="welcomeServlet">
Name :<input type="text" name="txtName"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Program save with Name: WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet
7. {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String name=request.getParameter("txtName");
PrintWriter out=response.getWriter();
out.println("<b> Welcome, "+name+"</b>");
Cookie ck=new Cookie("user",name);
response.addCookie(ck);
ck.setMaxAge(60); // for making Persisted Cookies
out.println("<br> <form action=tourServlet method=get>");
out.println("<br><input type=submit value="Take a Tour"></form>" );
out.close();
}
}
Program save with Name: TourServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TourServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String name="Gust";
Cookie ch[]=request.getCookies();
if(ch!=null)
name=ch[0].getValue();
out.println("<b> Sorry, "+name+"</b>");
out.println("<br>Site is down for routine maintenance, vist again later..");
out.close();
}
}
Program save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>welcomeServlet</url-pattern>
</servlet-mapping>
8. <servlet>
<servlet-name>s2</servlet-name>
<servlet-class>TourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>tourServlet</url-pattern>
</servlet-mapping>
</web-app>
Output :
Run program on two browser and test with both users one by one
Yes, now state is managed it will give correct output.
2- Hidden form field
Hidden form field provide the browser independent
method of maintaining state between requests. In this method information is
to persistence between one request to another is contain in invisible text
field which are added to the response page whenever a new request is
submitted using the response page value of invisible field are posted as
request parameter.
Limitation:
1- Only textual information can be persisted between requests.
2- This approach can only be used when request is submitted using the form
of response page that is this approach does not work with hyperlink.
Example 1- program for state management using Hidden form field.
9. Program save with Name: index.html
<html>
<head><title>Inter Application Forwarding..</title></head>
<body>
<form method="get" action="welcomeServlet">
Name :<input type="text" name="txtName"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Program save with Name: WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String name=request.getParameter("txtName");
PrintWriter out=response.getWriter();
out.println("<b> Welcome, "+name+"</b>");
out.println("<br> <form action=tourServlet method=get>");
out.println("<br><input type=hidden name=txtHidden
value=""+name+"">");
out.println("<br><input type=submit value="Take a Tour"></form>" );
out.close();
}
}
Program save with Name: TourServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TourServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String name=request.getParameter("txtHidden");
out.println("<b> Sorry, "+name+"</b>");
out.println("<br>Site is down for routine maintenance, vist again later..");
out.close();
}
10. }
Program save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>welcomeServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>TourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>tourServlet</url-pattern>
</servlet-mapping>
</web-app>
Output :
Run program on two browser and test with both users one by one
Yes, now state is managed it will give correct output.
3- URL rewriting (mostly used)
In this approach information to be persisted between request is dynamically
appended to the URL in response page, whenever a request is submitted
using these URL, append information is submitted as request parameters.
Syntax of appending:
URL?paramName=value & paramName=value
Limitation:
1- Only textual information can be persisted using this approach.
2- In case of input form this approach work only if post request is submitted
(Because get request changed the URL).
Example 1- program for state management using URL rewriting (Using Form
Field).
Program save with Name: index.html
11. <html>
<head><title>Inter Application Forwarding..</title></head>
<body>
<form method="get" action="welcomeServlet">
Name :<input type="text" name="txtName"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Program save with Name: WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String name=request.getParameter("txtName");
PrintWriter out=response.getWriter();
out.println("<b> Welcome, "+name+"</b>");
out.println("<br> <form method=post action="tourServlet?userName="+name+"">");
out.println("<br><input type=submit value="Take a Tour"></form>" );
out.close();
}
}
Program save with Name: TourServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TourServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String name=request.getParameter("userName");
if(name.equals(""))
name="Gust";
out.println("<b> Sorry, "+name+"</b>");
out.println("<br>Site is down for routine maintenance, vist again later..");
out.close();
}
}
12. Program save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>welcomeServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>TourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>tourServlet</url-pattern>
</servlet-mapping>
</web-app>
Output :
In this program we are using post method for submitting request on tourServlet that help
URL is overridden that is specified in program and if we using get request then new URL is
created instead of specified in program.
If we try to use get method then NullPointerException occure.
Example 1- program for state management using URL rewriting (Using Hyperlink).
Program save with Name: index.html
<html>
<head><title>Inter Application Forwarding..</title></head>
<body>
<form method="get" action="welcomeServlet">
Name :<input type="text" name="txtName"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Program save with Name: WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
13. public class WelcomeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String name=request.getParameter("txtName");
PrintWriter out=response.getWriter();
out.println("<b> Welcome, "+name+"</b>");
out.println("<br><a href="tourServlet?userName="+name+"">Take a
Tour</a>");
out.close();
}
}
Program save with Name: TourServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TourServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String name=request.getParameter("userName");
if(name.equals(""))
name="Gust";
out.println("<b> Sorry, "+name+"</b>");
out.println("<br>Site is down for routine maintenance, vist again later..");
out.close();
}
}
Program save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>welcomeServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
14. <servlet-class>TourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>tourServlet</url-pattern>
</servlet-mapping>
</web-app>
Output :
In this program use get method because Hyperlink is generate get request.
4- HttpSession
javax.servlet.http.HttpSession is an interface of Servlet API.
Implementation of which is provided by the vendors. An object of type
HttpSession can be get created by the web server per user. This object is
used by the application developer to store user information between
requests.
Commonly used method of HttpSession interface:
1- setAttribute():
Is used to store an attribute in the session scope.
public void setAttribute(String name, Object value);
2- getAttribute():
Is used to obtain an attribute from the session scope.
public Object getAttribute(String name);
3- getAttributeNames():
Is used to find out the names of attributes saved in
session scope.
public Enumeration getAttributeNames();
4- removeAttribute():
Is used to remove an attributes from the session scope.
public boolean removeAttribute(String name);
Methods used For management Session Object:
5- isNew():
Is used to find out whether session is created for the current
request or not.
public boolean isNew();
15. 6- setMaxInactiveInterval():
Is used to specify the time for which a session remains valid
even if no request is received from the client.
public void setMaxInactiveInterval(int second);
7-invalidate():
Is used to release a session.
public void invalidate();
etc…..
getSession():
getSession() method of HttpServletRequest interface is used
to obtain a HttpSession object.
public HttpSession getSession();
public HttpSession getSession(boolean createFlag);
Example 1- program for state management using HttpSession object.
Program save with Name: index.html
<html>
<head><title>Inter Application Forwarding..</title></head>
<body>
<form method="get" action="welcomeServlet">
Name :<input type="text" name="txtName"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Program save with Name: WelcomeServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
String name=request.getParameter("txtName");
PrintWriter out=response.getWriter();
out.println("<b> Welcome, "+name+"</b>");
HttpSession session=request.getSession();
session.setAttribute("uname",name);
16. session.setMaxInactiveInterval(3); // If user is ideal state max(3 second)
then
// Session object is destroyed.
out.println("<br><a href=" tourServlet ">Take a Tour</a>");
out.close();
}
}
Program save with Name: TourServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class TourServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
HttpSession session=request.getSession();
String name=(String)session.getAttribute("uname");
// session.invalidate(); // Use for destroy Session object.
if(name==null)
name="Guest";
out.println("<b> Sorry, "+name+"</b>");
out.println("<br>Site is down for routine maintenance, vist again later..");
out.close();
}
}
Program save with Name: web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>welcomeServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>TourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
17. <url-pattern>tourServlet</url-pattern>
</servlet-mapping>
</web-app>
Output :
Run program and test it frequently submitting request and wait 3 second then submit
request.
Yes, now state is managed it will give correct output.
In order to manage session object web server create unique id for each
session. Session object are store in a map by the server using the id as key.
Unique identifier for each session is sent with the response in the form of
cookies or request parameter using URL rewriting.
When subsequent request are submitted session id is made available which
is used by the server to identify the session.