I'm building small application, im kinda newbie in jsp..I use the MVC n servlets concepts..
My problem is after from servlets, the page i want to go (change to another place) cannot shown in the address bar correctly(the addressbar still showing the servlet page), but the view is exactly d same with the page i want to go..
I create a login page in file main.jsp, i send the data to ControlIndex servlet, n if login success go to mgmtActivity.jsp, all the error things while login i saved in the list errors.
This is my servlet code:
public class ControlIndex extends HttpServlet {
private List errors = new Vector();
private HttpSession session;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.close();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
session = request.getSession();
errors.clear();
boolean statusLogin = false;
String aksi = request.getParameter("aksi");
if (aksi.equals("login")){
String username = request.getParameter("username");
String password = request.getParameter("password");
User user = null;
// input validation
if ((username == null) || !username.trim().matches("^[a-zA-Z]+$")){
errors.add("Username cannot contains white space or non alphabetic characters.");
}
// execute
if (errors.size()==0){
user = User.getUser(username);
if (user == null){
errors.add("Cannot find those username.");
} else{
if (user.validatePassword(password)){
statusLogin = true;
} else{
errors.add("Wrong password.");
}
}
}
if (statusLogin){
//set session
session.setAttribute("user", user);
RequestDispatcher view = request.getRequestDispatcher("mgmtActivity.jsp");
try{
view.forward(request, response);
}catch(ServletException e){
e.printStackTrace();
}
}
}else if (aksi.equals("logout")){
//delete session
session.setAttribute("user", null);
}
if (errors.size()!=0){
request.setAttribute("errors", errors);
}
RequestDispatcher view = request.getRequestDispatcher("main.jsp");
try{
view.forward(request, response);
}catch(ServletException e){
e.printStackTrace();
}
}
}
Can anyone help me with this problem? Thanks before..:)