我有一个FormGetExample.html文件.内容如下:
<p> </p>
<form name="form1" method="post" action="http://localhost:8080/servlets/FromGetExamle1"> <table width="75%" height="273" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="35%">昵称</td> <td width="65%"><input name="nickname" type="text" id="nickname" value="aaaaaa"></td> </tr> <tr> <td>密码</td> <td><input name="password1" type="password" id="password1" value="aaaaaa"></td> </tr> <tr> <td>确认密码</td> <td><input name="password2" type="password" id="password2" value="aaaaaa"></td> </tr> <tr> <td>性别</td> <td><input name="gender" type="radio" value="1" checked> 男 <input type="radio" name="gender" value="2"> 女 <input type="radio" name="gender" value="0"> 保密</td> </tr> <tr> <td>爱好</td> <td><input name="fond" type="checkbox" id="fond" value="1" checked> 体育 <input name="fond" type="checkbox" id="fond" value="2"> 电脑 <input name="fond" type="checkbox" id="fond" value="3"> 音乐</td> </tr> <tr> <td>地区</td> <td><select name="select"> <option value="1" selected>上海</option> <option value="2">北京</option> </select></td> </tr> <tr> <td>隐藏域</td> <td><input name="hidden" type="hidden" id="hidden" value="this is a hidden field"></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"> </div></td> </tr> </table> </form> <p> </p>
截图如下:
我把这个文件放到了C:\Tomcat4\webapps\ROOT目录下,
然后,做了一个FormGetExample1.java文件,内容如下
import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Hello World!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello World!</h1>"); out.println("</body>"); out.println("</html>"); } }
我把这个文件放到了 C:\Tomcat4\webapps\ROOT\WEB-INF\servlets 目录下,
servlets目录是我自己建的,不知对不对.
然后编译后,在同一个目录下生成了一个 FormGetExample1.class文件.
我通过http://localhost:8080/FormGetexample.html访问这个文件,但是在提交的时间.出现如下错误,不知是什么原因,请指教.