I have two pages jsp pages First one is AppLogin.jsp and other one is Login.jsp
I want that when i click on Submit button of AppLogin.jsp page, i want redirect to Login.jsp page with password value and check this value on page load of Login.jsp page.
For this i did following code but the below code did not work.
I don't want to use Session and append value on url.
AppLogin.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>App Login</title>
</head>
<body>
<form action="loginServlet" method="post">
<table>
<tr>
<td>Application Name</td>
<td><input type="text" value="" name="txtApplication" /></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" value="" name="txtUsername" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" value="" name="txtPassword" /></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, ClientProtocolException {
try {
String password = req.getParameter("txtPassword");
req.setAttribute("crendential",password);
RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
rd.forward(req,res);
}
catch (Exception e) {
System.out.println("LoginServletException>>>>>>>>>>" + e);
}
}
}
Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<form action="saveServlet" method="post">
<table>
<tr>
<td>Application :</td>
<td><input type="text" value="" name="txtApplication" /></td>
</tr>
<tr>
<td>Username :</td>
<td><input type="text" value="" name="txtUsername" /></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="text" value="" name="txtPassword" /></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
public class SaveServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException {
try {
String crendential = (String) req.getAttribute("crendential");
System.out.println("crendential>>>>>>>>>>" + crendential);
}
catch (Exception e) {
System.out.println("LoginServletException>>>>>>>>>>" + e);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String crendential = (String) req.getAttribute("crendential");
System.out.println("crendential>>>>>>>>>>" + crendential);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>xyz</display-name>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>xyz.io.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/loginServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>save</servlet-name>
<servlet-class>xyz.io.SaveServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>save</servlet-name>
<url-pattern>/Login.jsp</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>AppLogin.jsp</welcome-file>
</welcome-file-list>
</web-app>
I am using Java with Eclipse Mars.