刚起步,做的是一个非常简单的连接数据库
在运行的过程中出现The requested resource (/web02/addEmp.html) is not available.
下面是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version ="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>addEmpServlet</servlet-name>
<servlet-class>web.AddEmpServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>addEmpServlet</servlet-name>
<url-pattern>/add</url-pattern>
</servlet-mapping>
<error-page>
<!--方式1-->
<error-code>500</error-code>
<!--方式2
<exception-type>javax.servlet.ServletException
</exception-type>
-->
<location>/error.html</location>
</error-page>
</web-app>
两个HTML文件:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>addEmp</title>
</head>
<body style="font-size: 30px;">
<form action="add" method="post;">
<fieldset>
<legend>添加雇员</legend>
姓名:<input name="name"/><br/>
薪水:<input salary="salary"/><br/>
年龄:<input age="age"/><br/>
<input type="submit" value="确认";/>
</fieldset>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>sorry.</title>
</head>
<body style="font-size: 30px;color: red;">
发生了系统错误,请歇会。
<a href="addEmp.html">try again!~</a>
</body>
</html>
以及主程序如下:
package web;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;