register.jsp文件:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"  errorPage="err_register2.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>欢迎注册普赛顿</title>
<link href="css/&#26032;&#28010;&#39318;&#39029;css.css" rel="stylesheet" type="text/css">
<link href="css/&#38597;&#34382;&#37038;&#20214;CSS.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
font-size: 14px;
font-weight: bold;
}
-->
</style>
</head>
<script language="javascript">function checkUserName()
{
//
if((form1.userName.value=="")||(form1.userName.value.length<4)||(form1.userName.value.length>17))
{
alert("注册名必须大于4位且小于16位!");
form1.flag.value="false";
}
else 
form1.flag.value="true";}function checkPassword()
{
//判断能密码位数
  
  if((form1.password.value.length<6)||(form1.password.value.length>17))
  {
   alert("密码必须大于6位且小于16位!");
  form1.flag.value="false";
  }
  if(form1.password.value!=form1.rePassword.value)
  {
  alert("输入的密码与确认密码不一致!");
  form1.flag.value="false";
  }
}
function checkMail()
{
if((form1.mail.value=="")||(form1.mail.value.indexOf('@')==-1)||(form1.mail.value.indexOf('.')==-1))
{
alert("请输入正确邮件地址!"); 
form1.flag.value="false";
}
else
return;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function ok()
{
checkUserName();
checkPassword();
checkMail();if(form1.flag.value=="true")
{
//在/servlet/InsertUserInfo中将数据写入数据库。
form1.action="/servlet/InsertUserInfo";form1.submit();
}
}function cancel()
{
form1.action="poseidon.html";
form1.submit();
}
</script>

解决方案 »

  1.   

    web.xml文件:
    <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
      <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
    <!-- JSPC servlet mappings start -->    <servlet>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <servlet-class>org.apache.jsp.index_jsp</servlet-class>
        </servlet>
      <servlet>
        <servlet-name>DBservlet</servlet-name>
        <display-name>InsertUser</display-name>
        <description>This is the description of my J2EE component</description>
        <servlet-class>com.poseidon.servlet.DBservlet</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>InsertUserInfo</servlet-name>
        <display-name>InsertUser</display-name>
        <description>This is the description of my J2EE component</description>
        <servlet-class>com.poseidon.servlet.InsertUserInfo</servlet-class>
      </servlet>    <servlet-mapping>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <url-pattern>/index.jsp</url-pattern>
        </servlet-mapping>
      <servlet-mapping>
        <servlet-name>DBservlet</servlet-name>
        <url-pattern>/servlet/DBservlet</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>InsertUserInfo</servlet-name>
        <url-pattern>/servlet/InsertUserInfo</url-pattern>
      </servlet-mapping><!-- JSPC servlet mappings end --></web-app>
      

  2.   

    首先你的form好像没有action属性赙值,另外web.xml里也没有servlet的设置
      

  3.   

    把action=""改成action="/servlet/DBServlet"
      

  4.   

    没事儿吧,找不到,你在web.xml里mapping了吗?
      

  5.   

    servlet需要在web.xml中进行相应的映射啊
      

  6.   

    对不起,刚才没看清楚,你的javascript,和web.xml中的配置都没有问题,我觉得你的connectionPool有问题,你的web服务器是什么,如果是tomcat的话需要在server.xml以及
    web.xml中进行配置jndi,如果是weblogic的话也需要相应的配置,另外你的数据库是什么呢?是mysql,还是oracle呢,他们的驱动是不是配的正确呢,可能是servlet访问数据问题也有可能,另外如果servlet找不到,可能是你的web服务器有了问题,最近我也碰到,访问我某个类时总说我该类的一个方法没有找到,希望进行更多的探讨。17423497
      

  7.   

    先谢谢大家了
    一楼和二楼的兄弟,我的action属性在javascript函数里进行判断后赋值了
    WEB。XML文件如下:(本来我想一起帖上去,可是CSDN说连续回帖不能超过三次)
    <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
      <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>
    <!-- JSPC servlet mappings start -->    <servlet>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <servlet-class>org.apache.jsp.index_jsp</servlet-class>
        </servlet>
      <servlet>
        <servlet-name>DBservlet</servlet-name>
        <display-name>InsertUser</display-name>
        <description>This is the description of my J2EE component</description>
        <servlet-class>com.poseidon.servlet.DBservlet</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>InsertUserInfo</servlet-name>
        <display-name>InsertUserInfo</display-name>
        <description>This is the description of my J2EE component</description>
        <servlet-class>com.poseidon.servlet.InsertUserInfo</servlet-class>
      </servlet>    <servlet-mapping>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <url-pattern>/index.jsp</url-pattern>
        </servlet-mapping>
      <servlet-mapping>
        <servlet-name>DBservlet</servlet-name>
        <url-pattern>/servlet/DBservlet</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>InsertUserInfo</servlet-name>
        <url-pattern>/servlet/InsertUserInfo</url-pattern>
      </servlet-mapping><!-- JSPC servlet mappings end --></web-app>
    我在IE里键入/servlet/InsertUserInfo,就不能打开(当然前面的localhost和端口号路径什么的都加了)楼上的兄弟,先谢了:
    我的WEB服务器是tomcat,我是通过tomcat的控制页面配置的server.xml,方法是(见下贴):
      

  8.   

    在http://localhost:8080/进入后,点左边的tomcat 
    administrator。输入你的密码,默认,用户名是admin,密码为空。如果忘记密码了。在tomcat目录下conf目录,有个tomcat-users.xml文件,里面有用户名和密码。
    进去之后,点service,host,context,找到你的虚拟目录,点左边的圆点。有一个data 
    source,点它,点右边的下来菜单create new datasource。
    JNDI Name: 随便起个名字比如:jdbc/mysql
    Data Source URL: 
    连接的url,jdbc:mysql://localhost:3306/你的数据库?useUnicode=true&characterEncoding=gb2312
    User Name: 用户名
    Password: 密码
    Max. Active Connections: 最大连接数
    Max. Idle Connections: 最大闲置连接
    Max. Wait for Connection: 等待数
    Validation Query: 这个我也没用过建好后,点save。重起tomcat。在你的tomcat目录下Catalina\localhost这个目录里,有个和你虚拟目录相同名字的xml。点开看看。里面有你配置连接池的信息。使用:DataSource ds = null;
    Connection conn = null;
    InitialContext initCtx = new InitialContext();
    ds = (DataSource) 
    initCtx.lookup("java:comp/env/jdbc/mysql");
    conn = ds.getConnection();我的数据库是my sql。我关于数据库的配置应该是正确的,因为我通过建立普通连接Connection conn = DriverManager.getConnection()得到连接后并对其操作时,可以正常访问数据库。我想在servlet写一个连接池,因为servlet是常驻内存的,于是就遇到了现在的问题。谢谢大家!帮帮忙了!
    谁都是从菜鸟走过来的,您一句话,就能帮我大忙了!
      

  9.   

    我就是按照上面配置连接池的文档配的连接池,这样SERVER。XML应该就已经自动配置了啊。而且在生成SERVLET的时候(我用的ECLIPSE),环境自动生成了配置WEB。XML的信息