新手,请问如何在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+ " ') ";
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(ClassNotFoundException e){
}
catch(SQLException ex){}
}
}
[解决办法]
去WEB-XML看看SERVLET配置正确否
[解决办法]
在web.xml里面添加如下代码
<servlet>
<servlet-name> post2 </servlet-name>
<servlet-class>
Post2 //这样的类就是你写的Post2 如果在包下 要带包名
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> post2 </servlet-name>
<url-pattern> /post2 </url-pattern>
</servlet-mapping>
[解决办法]
出售以下资料、代码
1.JSP编程技巧百问集锦(100个问题;一个问题一段代码) 报价:30 RMB
2.ASP编程技巧百问集锦(100个问题;一个问题一段代码) 报价:30 RMB
3.JavaScript编程技巧百问集锦(100个问题;一个问题一段代码) 报价:20 RMB
4. <在线书店系统> 大解密(jsp+javabean+servlet Web版 全套源码 安装即用) 报价:150 RMB
5. <办公自动化系统> 大解密(jsp+javabean+servlet Web版 全套源码 安装即用) 报价:300 RMB
需要者请联系:e_mail:fzlotuscn@yahoo.com.cn QQ:595563946
[解决办法]
试着将 <form name= "main " method= "post " action= "post2 " onsubmit= "return checkvalue "> 改为:
<form name= "main " method= "post " action= " <%=request.getContextPath()%> /post2 " onsubmit= "return checkvalue ">