日期:2014-05-18  浏览次数:20661 次

新手,请问如何在JSP里用JAVA文件执行数据添加功能?
是这样吗?
<form   name= "main "   method= "post "   action= "post2 "   onsubmit= "return   checkvalue ">
我的JAVA文件是post2

为什么点击JSP的添加按扭后显示:The   requested   resource   (/work/register/post2)   is   not   available.

POST2的文件:
import   java.sql.*;
import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;
import   java.util.Collection;

//import   jdbcbook.pub.util.*;

public   class   Post2   extends   HttpServlet{


public   void   doPost(HttpServletRequest   request,HttpServletResponse   response)   throws   IOException,ServletException{
//取得用户提交的参数
String   username   =   request.getParameter( "username ");
String   password   =   request.getParameter( "password ");
String   password2   =   request.getParameter( "password2 ");
String   email   =   request.getParameter( "email ");
String   address   =   request.getParameter( "address ");
String   idpost   =   request.getParameter( "idpost ");
String   tele   =   request.getParameter( "tele ");

username   =   new   String(username.getBytes( "ISO8859_1 "), "GBK ");
                password   =   new   String(password.getBytes( "ISO8859_1 "), "GBK ");
                email   =   new   String(email.getBytes( "ISO8859_1 "), "GBK ");
                address   =   new   String(address.getBytes( "ISO8859_1 "), "GBK ");
                idpost   =   new   String(idpost.getBytes( "ISO8859_1 "), "GBK ");
                tele   =   new   String(tele.getBytes( "ISO8859_1 "), "GBK ");



try{
                                          Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
                                          Connection   conn=DriverManager.getConnection( "jdbc:odbc:register ");
                                          java.sql.Statement   stmt=conn.createStatement();  
                                          String   sql= "insert   into   register(username,password,email,address,idpost,tele)   values( ' "+username+ " ', ' "+password+ " ', ' "+email+ " ', ' "+address+ " ', ' "+idpost+ " ', ' "+tele+ " ') &