新手,请教怎么在JSP里用JAVA文件执行数据添加功能


新手,请问如何在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( "ISO88591 "), "GBK ");
                password   =   new   String(password.getBytes( "ISO8859
1 "), "GBK ");
                email   =   new   String(email.getBytes( "ISO88591 "), "GBK ");
                address   =   new   String(address.getBytes( "ISO8859
1 "), "GBK ");
                idpost   =   new   String(idpost.getBytes( "ISO88591 "), "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+ " ') ";
                                          stmt.executeUpdate(sql);

                                          stmt.close();

相关链接

java JavaWeb开发 程序开发

成步堂龙叔 13 years, 1 month ago

Your Answer