java - Servlet mapping is not working -
i have created simple program using jsp , servlets. after all, have set , mapped servlet in web.xml below. getting blank page always.
<servlet> <servlet-name>example</servlet-name> <servlet-class>exampleservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>example</servlet-name> <url-pattern>/exampleservlet</url-pattern> </servlet-mapping>
my jsp file looks this.
<html> <head></head> <body> <form action ="exampleservlet" method="post" enctype="multipart/form-data"> <table width="500" style="margin-top:100px;"> <tr> <td>subject</td> <td><input type="text" name="subj" id="subj"/></td> </tr> <tr> <td>upload file</td> <td><input type="file" name="upload_file" id="upload_file"/></td> </tr> <tr> <td> </td> <td></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="upload" /></td> </tr> </table> </form> </body> </html>
any exampleservlet is,
import java.io.file; import java.util.list; import java.io.ioexception; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import java.io.printwriter; public class exampleservlet extends httpservlet { public void init() { } protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string sub = request.getparameter("subj"); system.out.println(sub); } }
my file structure is,
jsp file --> tomcat/webapps/application/index.jsp servlet --> tomcat/webapps/application/web-inf/classes/exampleservlet.class
where went wrong? mistake have made? can please suggest me?
edit : posting form elements servlet. time passes url http://localhost:8080/application/exampleservlet
everything fine in application. getting blank page because dopost
method doesn't anything. prints value console output.
change e.g.:
protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { printwriter writer = response.getwriter(); writer.print("something"); }
and take if something
appears in browser.
Comments
Post a Comment