User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 397,646 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,438 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 548 | Replies: 1
Reply
Join Date: Jul 2008
Posts: 1
Reputation: xray_slayer is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xray_slayer xray_slayer is offline Offline
Newbie Poster

URL in address bar,didnt change but the view is correct

  #1  
Jul 22nd, 2008
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..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2008
Posts: 8
Reputation: nikhildoomra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
nikhildoomra nikhildoomra is offline Offline
Newbie Poster

Re: URL in address bar,didnt change but the view is correct

  #2  
22 Days Ago
i think problem is with jsp...
u might be using frames...thatswhy..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 11:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC