JSP & Servlets
1.0.0
1.0.0
  • Setting up
  • Pre-requisites
  • Servlet Part 1
  • Servlet Part 2
  • Understanding the servlet
  • Servlet XML Configuration
  • POST method and passing parameters
  • Passing more parameters
  • Understanding GET and POST
  • Request, Session and Context Part -1
  • Request , Session and Context Part - 2
  • Understanding init, service and ServletConfig
  • Hello JSP
  • Understanding JSP
  • JSP Page directives
  • HttpServletRequest Path Decoding
  • Scopes in JSP and the PageContext Object
  • Understanding MVC pattern
  • PART -1 Writing an MVC app
  • JSTL
    • For-each
  • CRUD-1
  • Project Work
    • Create a Simple Java Web Application Using Servlet, JSP/JSTL and JDBC/Transaction
  • Locale Filter
  • Action Plan
    • Schedule
    • Hit webservice
Powered by GitBook
On this page

Was this helpful?

  1. Action Plan

Schedule

--index.html
--in welcome list give the name of servlet
--revert the things
--create login form in index.html with action as "login"
-- in dopost write method to authenticate uname and password with db
--print userbane and details on index.html

--create a new success.jsp and redirect  id correct cred


String userName = request.getParameter("username");
		String pswd = request.getParameter("password");
		if (userName == "Admin" && pswd == "Admin") {
			response.sendRedirect("success.jsp");
		}

--
--use of session to display username

if (userName.equals("Admin") && pswd.equals("Admin")) {
			request.getSession().setAttribute("username", userName);
			response.sendRedirect("success.jsp");
		} else {
			response.sendRedirect("Index.html");
		}

---on jsp---
<%=request.getSession().getAttribute("username")%>

--- use jstl to get the username on jsp---
download jar : 
https://mvnrepository.com/artifact/org.glassfish.web/javax.servlet.jsp.jstl/1.2.5
prefix: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<br> Hello ${username} in success.jsp

-- want to see request attribute 			request.setAttribute("user", "userTest");
on success.jsp without setting it in session?

---use--- 

request.setAttribute("user", "userTest");
			RequestDispatcher requestDispatcher = request.getRequestDispatcher("success.jsp");
			requestDispatcher.forward(request, response);

--sendridirect after forward
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
	at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:488)

diff b/w forward and include

RequestDispatcher requestDispatcher = request.getRequestDispatcher("success.jsp");
			requestDispatcher.forward(request, response);
			response.getWriter().println("back to servlet"); // this wont b displayed
PreviousLocale FilterNextHit webservice

Last updated 6 years ago

Was this helpful?