tomcat - Try to run a web application with a html page in Intellij IDEA but get 404 error -
i want simple thing: let user input username , password, show on second page. use tomcat 8 server. here key codes:
login.html:
<!doctype html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> <title>login</title> </head> <body> <div align="center"><h1>login in</h1> <form method="post" action="getpostdata" name="login form" align="center"> <table align="center" width="232" border="2"> <tr> <td>username</td> <td><input type="text" name="username"></td> </tr> <tr> <td>password</td> <td><input type="text" name="password"></td> </tr> </table> <input type="reset" value="reset" name="reset"> <input type="submit" value="submit" name="submit"> </form> </div> </body> </html>
web.xml:
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>getpostdata</servlet-name> <servlet-class>com.ywwynm.getpostdata</servlet-class> </servlet> <servlet-mapping> <servlet-name>getpostdata</servlet-name> <url-pattern>/getpostdata</url-pattern> </servlet-mapping> </web-app>
getpostdata.java:
package com.ywwynm; import javax.servlet.servletexception; import javax.servlet.annotation.webservlet; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import java.io.ioexception; import java.io.printwriter; @webservlet(name = "getpostdata") public class getpostdata extends httpservlet { public void processrequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { printwriter out = response.getwriter(); out.println( "<body bgcolor=\"#fdf5e6\">\n"+ "<h1 align=center>" +"getpostdata"+"</h1><br>"+ "<ul>\n"+ "<l1><b>username:"+request.getparameter("username")+"<br>"+ "<l1><b>password:"+request.getparameter("password")+"<br>"+ "</ul>"+"\n"+ "</body>"+ "</html>" ); out.close(); } @override protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { processrequest(req, resp); } @override protected void dopost(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { processrequest(req, resp); } }
but when click run on login.html, shows static web page login.html. after input informations , click submit, 404 error jump page.
i've set compiled class directory web/web-inf/classes.
some clues:
- the url of running login.html doesn't start localhost:8080 number.
- intellij reminded me cannot resolve file "getpostdata" in login.html(at
action="getpostdata"
). - i clicked run on login.html didn't find approach run whole module.
i googled how develop web application intellij of them took auto-generated index.jsp example. result, don't know if should other preparations make work. please help. in advance!
i found login.html isn't in folder web
. move web
, works well.
Comments
Post a Comment