0% found this document useful (0 votes)
10 views1 page

Java Session Serverlt

Uploaded by

Sumit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Java Session Serverlt

Uploaded by

Sumit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SessionSaverServlet.

java

1 package com.meroProgram.sessionExample;
2
3 import java.io.IOException;
12
13 @WebServlet(urlPatterns = "/saver")
14 public class SessionSaverServlet extends HttpServlet{
15
16 @Override
17 protected void doGet(HttpServletRequest request, HttpServletResponse
response)throws ServletException,IOException{
18 //set response type to text/html
19 response.setContentType("text/html");
20
21 //fetch name of user from form
22 String name=request.getParameter("user");
23
24 PrintWriter out = response.getWriter();
25 out.println("<h3>Hello "+name+" </h3>");
26
27 //store name in session object
28 HttpSession session = request.getSession();
29 session.setAttribute("userName", name);
30
31 //dispatch request to next servlet
32 request.getRequestDispatcher("retriever").forward(request,
response);
33 }
34 }
35

Page 1

You might also like