•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 392,048 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 4,339 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: 469 | Replies: 1
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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:
Can anyone help me with this problem? Thanks before..
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();
}
}
}
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
Other Threads in the JSP Forum
- Previous Thread: JSF HTTP 500 error
- Next Thread: Using Beans in jsp....PLEASE HELP ME STUCK BADLY From 9 days


Linear Mode