I'm forwarding to a jsp that shows a table and a form for comments populated by jstl sql tags.
The problem is that the form works fine if I use response.sendRedirect("comments.jsp");
But since I need to retain session info between pages I want to use request.getRequestDispatcher("comments.jsp").forward(request, response);
which triggers the post form and redirects subsequent posts to the servlet url.
LoginServlet
public class LoginServlet extends HttpServlet {
Connection connection = null;
PreparedStatement ptmt = null;
ResultSet resultSet = null;
User user = null;
boolean fail = true;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String email = request.getParameter("email");
String password = request.getParameter("password");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
if (null != email && null != password) {
try {
connection = ConnectionFactory.getInstance().getConnection();
user = new User();
String queryString = "SELECT * FROM USERINFO WHERE EMAIL=?";
ptmt = connection.prepareStatement(queryString);
ptmt.setString(1, email);
resultSet = ptmt.executeQuery();
resultSet.next();
user.setEmail(resultSet.getString("EMAIL"));
...
user.setSecret3(resultSet.getString("SECRET3"));
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
}
}
if (null != user.getPassword() && user.getPassword().equals(password)) {
request.setAttribute("user",user);
request.getRequestDispatcher("comments.jsp").forward(request, response);
// response.sendRedirect("comments.jsp");
}
comments.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Comments</title>
</head>
<body>
<sql:setDataSource var="dataSource" driver="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/mp1"
user="app" password="app"/>
<sql:setDataSource var="dataSource2" driver="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/mp1"
user="app" password="app"/>
<H2>Comments</H2>
<sql:query dataSource="${dataSource}" sql="SELECT * FROM COMMENTS" var="comments" />
<table border=1>
<c:forEach var="row" items="${comments.rows}">
<tr>
<c:forEach var="col" items="${row}">
<td><c:out value="${col.value}" /></td>
</c:forEach>
</tr>
</c:forEach>
</table>
<form method="post">
<table>
<tr>
<td>Enter Email</td>
<td><input type="text" name="EMAIL"></td>
</tr>
<tr>
<td>Enter Comment</td>
<td><input type="text" name="COMMENT"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</form>
<c:if test="${pageContext.request.method=='POST'}">
<c:catch var="exception">
<sql:update dataSource="${dataSource2}" var="updatedTable">
INSERT INTO
COMMENTS (EMAIL,COMMENT)
VALUES (?, ?)
<sql:param value="${param.EMAIL}" />
<sql:param value="${param.COMMENT}" />
</sql:update>
<c:if test="${updatedTable>=1}">
<c:redirect url="/comments.jsp"/>
</c:if>
</c:catch>
<c:if test="${exception!=null}">
<c:out value="Unable to add comment." />
</c:if>
</c:if>
</body>
</html>
BTW, this is a homework assignment were the teacher wants us learn how it was done the old way. So security and better technologies to use are not real concerns.
PS. I've solved this by separating the comments and add comment into separate pages. Perhaps a better solution would be to use the session instead of the request for object transfer.
Both redirect and forward should retain session since session is supported by cookies (in most cases).
Your form doesn't have action parameter thus its behavior depends on the browser current URL (form gets posted to current URL instead of defined in action), and current URL is different in case of redirect and forward.
Related
I'm a beginner programmer, I already build page for data entry and page show all entries, but now I want to show specific row inside the table, which code can help me?
My table columns: fullname - email - Phone - education
I want to search by email to show the other data in one page.
I found this code on internet:
<%#page import="java.sql.*"%>
<% Class.forName("com.mysql.jdbc.Driver");%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
public class Showit {
String URL = "jdbc:mysql://localhost/regdata";
String USERNAME = "root";
String PASSWORD = "admin";
Connection conn = null;
PreparedStatement selectRegister = null;
ResultSet resultSet = null;
public Showit() {
try {
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
selectRegister = conn.prepareStatement(
"SELECT a.fullname, a.email,"
+ " FROM mainr a,"
+ "WHERE a.fullname = ?"
+ "AND a.email = ?");
} catch (Exception e) {
e.printStackTrace();
}
}
public ResultSet getShowit(String fullname, String email) {
try {
selectRegister.setString(1, fullname);
selectRegister.setString(2, email);
resultSet = selectRegister.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
return resultSet;
}
}
%>
<%
String fullname = new String();
String email = new String();
if (request.getParameter("fullname") != null) {
fullname = request.getParameter("fullname");
}
if (request.getParameter("email") != null) {
fullname = request.getParameter("email");
}
Showit showit = new Showit();
ResultSet showits = showit.getShowit(fullname, email);
%>
<table border="1">
<tbody>
<tr>
<td>Full Name</td>
<td>Email</td>
<td>Title</td>
</tr>
<% while (showits.next()) {%>
<tr>
<td><%= showits.getString("fullname")%></td>
<td><%= showits.getString("email")%></td>
<td><%= showits.getString("Phone")%></td>
</tr>
<% }%>
</tbody>
</table>
</body>
</html>
which connect with this page:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.sql.*"%>
<%#page import="java.util.Scanner" %>
<% Class.forName("com.mysql.jdbc.Driver");%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search</title>
</head>
<body>
<form name="search" action="display.jsp" method="POST">
<table border="0">
<tbody>
<tr>
<td>Full Name</td>
<td><input type="text" name="fullname" value="" size="50" /></td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="text" name="email" value="" size="50" /></td>
</tr>
</tbody>
</table>
<input type="reset" value="Reset" name="reset" />
<input type="submit" value="Submit" name="Submit" />
</form>
</body>
</html>
but it's not work.
The issue may be with this line:
fullname = request.getParameter("email");
Note that you are assigning the email parameter to the fullname variable.
first what i see is that the Query is wrong. Remove the , after the table alias "a" (here line 2) like this:
"SELECT a.fullname, a.email,"
+ " FROM mainr a"
+ "WHERE a.fullname = ?"
+ "AND a.email = ?");
There is also an issue here:
<td><%= showits.getString("Phone")%></td>
You did not include Phone in the SELECT statement, so it will not exist in the ResultSet.
I have a success.jsp page which displays multiple rows and columns with an Edit button and a checkbox for each row. If the user clicks on Edit button, the checkbox is selected.
Below is success.jsp :
<%#page import="mymvc.model.TableColumns"%>
<%#page import="java.util.ArrayList"%>
<%#page import="java.util.Iterator"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%--
Document : success
Created on : Jul 8, 2014, 1:43:17 PM
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Success</title>
<script type="text/javascript">
function validate(n) {
v = document.getElementById("check"+n)
v.checked = !v.checked;
x = document.getElementById("typeId"+n).removeAttribute('readonly');
y = document.getElementById("paramSeq"+n).removeAttribute('readonly');
z = document.getElementById("paramName"+n).removeAttribute('readonly');
}
</script>
</head>
<body>
<form action="DBController" method="post">
Welcome ${requestScope['user'].username}.
<table>
<tr style="background-color:#f0a64e;">
<th class="border">ID</th>
<th class="border">Param Sequence</th>
<th class="border">Param Name</th>
</tr>
<c:forEach var="element" items="${requestScope['listData']}" varStatus="status">
<tr>
<td><input id="typeId${status.index}" value="${element.typeId}" readonly="true"</td>
<td><input id="paramSeq${status.index}" value="${element.paramSeq}" readonly="true"</td>
<td><input id="paramName${status.index}" value="${element.paramName}" readonly="true"</td>
<td>
<input id="edit${status.index}" type="button" value="Edit" name="edit" onclick="validate(${status.index})"</input>
</td>
<td><input type="checkbox" id="check${status.index}" name="selectedItems" value="<c:out value="${status.index}"/>"</td>
</tr>
</c:forEach>
</table>
<input type="submit" value="Update" name="update" />
</form>
</body>
</html>
I don't know how to send the whole row data to my servlet if more than one row is selected. I am able to get all the indexes of the checkboxes which are selected. But I am unable to extract other related values like typeId, paramSeq and paramName. My servlet is as follows :
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String[] edited = request.getParameterValues("selectedItems");
//String pName = request.getParameter("paramName"+edited[1]);
Enumeration<String> paramName = request.getParameterNames();
String[] param = new String[10];
int i=0;
while(paramName.hasMoreElements()){
param[i]=paramName.nextElement();
}
RequestDispatcher rd = null;
rd = request.getRequestDispatcher("/update.jsp");
request.setAttribute("param", param);
request.setAttribute("edited", edited);
rd.forward(request, response);
}
In the above code, currently, I am trying to get all the parameters passed and the rows which are selected. I want to modify this servlet and access the selected row along with other data like typeId, etc. to create UPDATE statements for every row. I referred this and this but not much help.
I think what you are missing is that you are giving each input type a unique id but you are not specifying the name of the input types, and in the servlet you are trying to get values by name.
So please add names along with the id's in order to get them in the servlet
<c:forEach var="element" items="${requestScope['listData']}" varStatus="status">
<tr>
<td><input name="typeId${status.index}" value="${element.typeId}" readonly="true"</td>
<td><input name="paramSeq${status.index}" value="${element.paramSeq}" readonly="true"</td>
<td><input name="paramName${status.index}" value="${element.paramName}" readonly="true"</td>
<td>
<input id="edit${status.index}" type="button" value="Edit" name="edit" onclick="validate(${status.index})"</input>
</td>
<td><input type="checkbox" id="check${status.index}" name="selectedItems" value="<c:out value="${status.index}"/>"</td>
</tr>
</c:forEach>
</table>
I have searched this forum and net for this, found many example but still i am not able to populate the select box in jsp.
I have written a jsp servlet, where servlet returns an arraylist and in jsp uhsing jstl i am trying to create a select box and populating option with arraylist values.
Following is my code.
Servlet Code:
#SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response) {
UserService userService = new UserServiceImpl();
try {
String[] questions = userService.getQNA().getQuestions();
List<String> ques = new ArrayList<String>();
ques = Arrays.asList(questions);
request.setAttribute("questionDTO", ques);
response.sendRedirect("forms/enrollMigrationUser.jsp");
} catch (IOException e) {
log.error("request failed "+ e.getMessage());
}
}
JSP code :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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>Enroll Migration Users</title>
</head>
<body>
<form method="post" action="/nycb/enrolluser" name="enrollForm">
<table>
<tr>
<td>User setup</td>
<td></td>
</tr>
<tr>
<td>UserId :</td>
<td><input type="text" name="userName" id="userName"/></td>
</tr>
<tr>
<td>Password :</td>
<td><input type="password" name="password" id="password"/></td>
</tr>
<tr>
<td><input type="checkbox" name="computerType" value="public">Authorize this computer</td>
<td></td>
</tr>
<tr>
<td>
<select name='role'>
<c:forEach items="<%=request.getAttribute(\"questionDTO\") %>" var="question">
<option value="<c:out value="${question}"/>"><c:out value="${question}"/></option>
</c:forEach>
</select>
</td>
<td><input type="text" name="qna6" id="qna6"/></td>
</tr>
<tr>
<td>
<select name='role'>
<c:forEach items="${questionDTO}" var="question">
<option value="<c:out value="${question}"/>"><c:out value="${question}"/></option>
</c:forEach>
</select>
</td>
<td><input type="text" name="qna6" id="qna6"/></td>
</tr>
</table>
<input type="submit" value="click" name="dropdown" id="dropdown">
</form>
I am not able to populate the select box, the option field is empty.
Can anyone please let me know where i am going wrong?
sendRedirect() creates a new request and any attribute set in request will not be available in redirected JSP page.
Try any one
You can use RequestDispatcher#forward or RequestDispatcher#include in this case.
You can save it in session as attribute.
Sample code:
RequestDispatcher view = request.getRequestDispatcher("forms/enrollMigrationUser.jsp");
view.forward(request, response);
OR
HttpSession session = request.getSession();
session.setAttribute("questionDTO", ques);
response.sendRedirect("forms/enrollMigrationUser.jsp");
Always try to avoid Scriplet elements instead use JSTL & EL.
You can do in this to read an attribute from any scope in order page, request, session and finally applicaion
<c:forEach items="${questionDTO}" var="question">
OR read from specific scope.
<c:forEach items="${requestScope.questionDTO}" var="question">
This question already has answers here:
How to transfer data from JSP to servlet when submitting HTML form
(4 answers)
Closed 6 years ago.
I am trying to read the input by the user as soon as he clicks on a button. But unfortunately the request.getParamater() is always returning a null value. Can someone please help me I have been hours Trying to sort this out :(
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<%# page import="javax.servlet.http.*,javax.servlet.*" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<html>
<head>
<script language="javascript">
function add()
{
<%
Integer quantity = 500;
Integer code = 1000;
//String codes = request.getParameter("code");
String codes = (String) request.getParameter("code");
String quanti = (String) request.getParameter("quantity");
if (codes != null && quanti != null) {
quantity = Integer.parseInt(quanti);
code = Integer.parseInt(codes);
}
out.println(code);
out.println(quantity);
String connectionURL = "jdbc:mysql://localhost:3306/products";
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
// check if the text box is empty
if (code != null && quantity != null) {
// check if the text box having only blank spaces
if (codes != "" && quanti != "") {
try {
/* Create a connection by using getConnection()
method that takes parameters of string type
connection url, user name and password to connect
to database. */
connection = DriverManager.getConnection(connectionURL, "root", "170293m");
// sql query to insert values in the secified table.
String queryString = "INSERT INTO sales (code, quantity, price, name) VALUES (?, ?, ?, ?)";
/* createStatement() is used for create statement
object that is used for
sending sql statements to the specified database. */
pstatement = connection.prepareStatement(queryString);
pstatement.setInt(1, code);
pstatement.setInt(2, quantity);
pstatement.setDouble(3, 50);
pstatement.setString(4, "aw ras");
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) {
out.println("Error in query");
}
} catch (Exception ex) {
out.println("Unable to connect to batabase.");
} finally {
// close all the connections.
pstatement.close();
connection.close();
}
}
}%>
print();
}
function remove()
{
}
</script>
<title>BestWholesaler LTd.</title>
</head>
<body>
<h1>Welcome to BestWholesaler Ltd. Online Ordering</h1>
<h2>Items Currently in Stock</h2>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/products"
user="root" password="170293m"/>
<sql:query dataSource="${snapshot}" var="result">
SELECT Name, Code, PricePU, Quantity from productinfo;
</sql:query>
<table border="1" width="100%">
<tr>
<th>Name</th>
<th>Code</th>
<th>Price/Unit</th>
<th>Quantity Available</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td><c:out value="${row.Name}"/></td>
<td><c:out value="${row.Code}"/></td>
<td><c:out value="${row.PricePU}"/></td>
<td><c:out value="${row.Quantity}"/></td>
</tr>
</c:forEach>
</table>
<br>
<br>
Enter Code: <input type="text" name="code" id="code" value="" />
<br>
Enter Quantity: <input type="text" name="quantity" id="quantity" value="" />
<input type="button" value="ADD" name="add" onclick="add()" />
<input type="button" value="REMOVE" name="remove" onclick="remove()" />
</body>
</html>
You are not using any <form> HTML tag. All input tag must go inside it, and the button click should do a submit of the form.
By the way, you are mixing Javascrit client code and Java server code in a way that cannot work, you have different rendering timings.
On this example, assuming you are wanting to have a unique component both for client-side and for server-side, as you are doing, you can add the following to your JSP. For commodity I'm going to separate client-side and server-side logics.
Client side
<script>
function flagLoaded(){
document.forms[0]["loaded"].value = "true";
}
</script>
<form name="input" action="myself.jsp" method="get" onsubmit="flagLoaded()">
<!-- put here all your client-side's inputs -->
<!-- ... TODO ... -->
<input type="hidden" name="loaded" value="false">
<input type="submit" value="Submit">
</form>
Server side
<%
if("true".equals(request.getParameter("loaded"))){
//TODO
/*
Do here server-side logic...
*/
}
%>
The main reason behind this is you are using the javascript i.e <script language="javascript"> and you are trying to run the server side code inside it .
you must close the javascript by using </script> and then try to run the server side code..
You don't need javascript here, go with basic html form tag to submit the details. Also don't use scriplets as you are already aware of jstl. Note below code is only implemented for add, you need to write your code for remove.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/products" user="root" password="170293m" />
<title>BestWholesaler LTd.</title>
<style>
.error {
color: red;
}
</style>
<body>
<h1>Welcome to BestWholesaler Ltd. Online Ordering</h1>
<h2>Items Currently in Stock</h2>
<!-- add button was clicked -->
<c:if test="${null != param.add}">
<c:catch var="error">
<sql:update dataSource="${snapshot}" scope="page" var="result">
INSERT INTO sales (code, quantity, price, name) VALUES (?, ?, ?, ?)
<sql:param value="${param.code}" />
<sql:param value="${param.quantity}" />
<sql:param value="50" />
<sql:param value="aw ras" />
</sql:update>
</c:catch>
</c:if>
<!-- error occured -->
<c:if test="${null != error}">
<div class='error'>
Failed to save stock details
</div>
</c:if>
<c:catch var="error">
<sql:query dataSource="${snapshot}" var="result">
SELECT Name, Code, PricePU, Quantity from productinfo;
</sql:query>
</c:catch>
<c:if test="${null != error}">
<div class='error'>
Failed to get stock details
</div>
</c:if>
<c:if test="${null == error}">
<table border="1" width="100%">
<tr>
<th>Name</th>
<th>Code</th>
<th>Price/Unit</th>
<th>Quantity Available</th>
</tr>
<c:forEach var="row" items="${result.rows}">
<tr>
<td>
<c:out value="${row.Name}" />
</td>
<td>
<c:out value="${row.Code}" />
</td>
<td>
<c:out value="${row.PricePU}" />
</td>
<td>
<c:out value="${row.Quantity}" />
</td>
</tr>
</c:forEach>
</table>
</c:if>
<br/>
<br/>
<form method='post'> <!-- no action required, still you can give the same jsp file name -->
Enter Code:
<input type="text" name="code" />
<br/>Enter Quantity:
<input type="text" name="quantity" />
<input type="submit" value="ADD" name="add" />
</form>
</body>
Getting error:
java.lang.IllegalStateException: getAttributeNames: Session already invalidated.After logout from parent window.
LogOutUserAction.java
public String execute() throws Exception {
System.out.println("inside :: LogOutUserAction------");
//HttpServletRequest request = null;
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session =request.getSession(true);
session.removeAttribute("loggedInUser");
request.getSession(false).invalidate();
session=null;
return "logout";
}
LoginInterceptor
public String intercept(ActionInvocation invocation) throws Exception {
final ActionContext context = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) context
.get(HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) context
.get(HTTP_RESPONSE);
HttpSession session = request.getSession(true);
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
/*user logged out from the parent window then set the message
for click on the popup window*/
if(session == null){
System.out.println("set the attribute");
request.setAttribute("SessionExpired","Your have already logged out");
}
Object user = session.getAttribute(USER_HANDLE);
String loginOut = request.getParameter(LOGIN_OUT);
System.out.println("loginOut---->"+loginOut);
if (user == null) {
// The user has not logged in yet.
System.out.println(" inside if ");
// Is the user attempting to log in right now?
String loginAttempt = request.getParameter(LOGIN_ATTEMPT);
/* The user is attempting to log in. */
if (!StringUtils.isBlank(loginAttempt)) {
return invocation.invoke();
}
return "login";
} else {
return invocation.invoke();
}
}
login.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
if (request.getAttribute("SessionExpired")!= null)
{
System.out.println("After Session invalid");
}
%>
<html>
<head>
<title>Login</title>
<sx:head cache="true"/>
<script type="text/javascript">
</script>
<script type="text/javascript" language="javascript" src="js/login.js"></script>
<style type="text/css">
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style2 {
color: #000099
}
</style>
</head>
<body bgcolor="#CODFFD" background="<%request.getContextPath();%>images/watermark_new.jpg">
<br>
<br>
<br>
<br>
<br>
<br>
<div align="center"><span class="style1">USER LOGIN</span>
<br>
<br>
<br>
<s:form action="checkUserLogin.action" validate="true" name = "loginForm">
<s:hidden name="loginAttempt" value="%{'1'}" />
<table border="0" cellspacing="1" cellpadding="0" width="350" >
<tr>
<td align="center">
<b>Login ID</b>
</td>
<td>
<table>
<s:textfield id="id" name="loginId" value="" />
</table>
</td>
</tr>
<tr>
<td align="center">
<b>Password</b>
</td>
<td>
<table>
<s:password id="password" name="loginPassword" value="" showPassword="true"/>
</table>
</td>
</tr>
<tr><td colspan="2" align="center">
<table>
<s:submit value="Login" onclick = "return getRoleList()"/>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table>
<s:a href="changePasswordScreen.action" >Change Password</s:a>
</table>
</td>
</tr>
</table>
</s:form>
</div>
<br>
<br>
<br>
</body>
</html>
Need to display message on popup window (when i click on any link) as i mentioned on my login jsp after logout from parent window.
Interceptors can execute code before and after an Action is invoked. When is yours being invoked? I would imagine what's happening is this:
In LogOutUserAction.java you invalidate the session
LoginInterceptor.intercept is then executed. This tries to get an attribute from the session object that you invalidated hence the IllegalStateException.
Why are you invalidating the session? Your LoginInterceptor is using the presence of the USER_HANDLE attribute to indicate whether or not the user is logged in. I would remove this attribute in your LogOutUserAction but don't invalidate the session.