Hello,
In Servlet I'm trying to redirect to another page using both RequestDispatcher and sendRedirect bu t bith are seem to be not working.
What can I do?
Thank You
Views
Replies
Total Likes
Views
Replies
Total Likes
package com.mindtree.travellingdiva.core.servlets;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import com.mindtree.travellingdiva.core.dbservice.TDService;
@Component(service=Servlet.class,
property={
Constants.SERVICE_DESCRIPTION+"= Header Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_POST,
"sling.servlet.paths=/bin/LoginServlet",
"sling.servlet.resourceTypes="+"travellingdiva/components/structure/login",
"sling.servlet.extensions="+"txt"
})
public class LoginServlet extends SlingAllMethodsServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
@Reference
TDService service;
@Override
protected void doPost(final SlingHttpServletRequest req, final SlingHttpServletResponse res) throws IOException
{
String username = req.getParameter("uname");
String password = req.getParameter("pass");
String st;
boolean result = service.verifyUser(username,password);
if(result==true)
{
HttpSession session = req.getSession();
st=""+session.getAttribute("username")+" ";
st=st+"User Exist ";
session.setAttribute("username", username);
session.setMaxInactiveInterval(1800);
st=st+session.getAttribute("username");
}
else
st="Invalid username/password";
//res.getWriter().write(st);
res.sendRedirect("/content/travellingdiva/project/home.html");
//RequestDispatcher rd = req.getRequestDispatcher("/content/travellingdiva/project/home.html");
/*try {
rd.include(req, res);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
}
Views
Replies
Total Likes
Hi,
I created a demo servlet like yours and it is working as expected and redirecting to target page when I hit http://localhost:4502/bin/LoginServlet.txt
aem63app-repo/LoginServletRedirect.java at master · arunpatidar02/aem63app-repo · GitHub
Can try to same or check your code where it is failing ?
Views
Replies
Total Likes
For me Session is being set but I'm not able to call the Website, even it is not giving any exceptions,
Views
Replies
Total Likes
It is Staying in same page
Views
Replies
Total Likes
Can you try to put some logger before below code and check if code is executed to not?
res.sendRedirect("/content/travellingdiva/project/home.html");
Views
Replies
Total Likes
I've added, It is logged in the log file file, but still page has not changed.
Views
Replies
Total Likes
Hi,
Can you check error.log?
did you try servlet which I created?
Views
Replies
Total Likes
I've tried but no luck...Thank you for your valuable time...
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies