user1986761
user1986761

Reputation: 229

JSP Refresh Page Header

 <%@ include file="header.jsp" %>

<% 
//code here to check user login
%>

<%@ include file="footer.jsp" %>

How can I refresh the header page (which displays a welcome message) inside the code which checks user login (I don't want to refresh the whole page already tried that just the header.jsp) Thanks

Upvotes: 1

Views: 1422

Answers (2)

rikket
rikket

Reputation: 2407

I have had a similar problem. Best way to solve it is by creating a servlet which handles all login code and then send a response.SendRedirect() back to this page.

Upvotes: 2

BalusC
BalusC

Reputation: 1108922

That's not possible. It's too late. JSP writes to the response directly while executing the code in scriptlets. Just rearrange the code logic. You should perform business logic before emitting any HTML.

<% 
    // Code here to check user login and prepare variables.
%>

<%@ include file="header.jsp" %>

<% 
    // Code here to print necessary HTML based on prepared variables.
%>

<%@ include file="footer.jsp" %>

If you was using a normal servlet or filter the MVC way, you'd never have faced this problem.

Upvotes: 1

Related Questions