Search code examples
javajavascriptjspjsp-tags

Can we redirect one jsp page to another jsp page


I want to open a jsp page without accessing my servlete code. i.e. I neither have to input my url in (action="url") my jsp code nor have to access my Servlete code.

<form id="main" method="post" name="main" action="dpRegPost" onsubmit="return validate();">

Can anyone help me in this?


Solution

  • Try this:

    <form id="main" method="post" name="main" action="" onsubmit="redirect(this);">
        <input type="submit" name="submit"/> 
    </form>
    
    
    function redirect(elem){
         elem.setAttribute("action","somepage.jsp");
         elem.submit();
    }