Exception Handling in Jsp -


how handle exception without sending error page? how set message detail exception object?(not using jstl tags)

thanks, ravi

not using jstl tags

i going suggest c:catch, don't want use jstl, stops here.

still then, have been bad idea. don't want use jsp business logic. use (indirectly) servlet this. servlets can control, preprocess and/or postprocess requests , forward request jsp file in turn displays data using el , controls page flow dynamically using taglibs <jsp:xxx> , jstl.

here's basic example based on "login user" idea:

protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {     string username = request.getparameter("username");     string password = request.getparameter("password");      if (username == null || username.isempty() || password == null || password.isempty()) {         request.setattribute("error", "please enter both username , password.");     } else {         user user = userdao.find(username, password);         if (user == null) {             request.setattribute("error", "unknown login, please try again.");         } else {             request.getsession().setattribute("user", user);             request.setattribute("succes", "login succesful!");         }     }      request.getrequestdispatcher("login.jsp").forward(request, response); } 

and basic jsp example:

<form action="login" method="post">      username: <input type="text" name="username" value="${param.username}"><br>      password: <input type="password" name="password" value="${param.password}"><br>      login: <input type="submit" value="login"><br>      <span class="error">${error}</span>      <span class="succes">${succes}</span> </form> 

you go further using example map<string, string> messages can attach error message every input field. go further using mvc framework takes work hands, that's story ;)


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -