做了一个jsp的表单,用的是Myeclipse,怎样把把数据传到后台的oracle数据库中自己建立的名叫的user表中储存 100
以下是我做的表单程序,希望能有高手帮助一下,做出后台的程序来。。谢谢了。。。<body><%Class.forName("oracle.jdbc.driver.Oracl...
以下是我做的表单程序,希望能有高手帮助一下,做出后台的程序来。。谢谢了。。。
<body>
<% Class.forName("oracle.jdbc.driver.OracleDriver");
//System.setProperty("jdbc.drivers","oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
Connection conn=DriverManager.getConnection(url,"TEST","zhang");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from users"); %>
<form action="" method="post" />
姓名:<input type="text" name="username"/><br>
学号:<input type="text" name="passwd"/><br>
电话:<input type="text" name="email"/><br>
<input type="submit" value="提交" />
</form>
<form action="index.jsp" method="post">
<input type="submit" value="返回"/>
</form>
本人是小白,所以希望能够写得明白一点儿,最好是能把程序帮忙写出来。。。 展开
<body>
<% Class.forName("oracle.jdbc.driver.OracleDriver");
//System.setProperty("jdbc.drivers","oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
Connection conn=DriverManager.getConnection(url,"TEST","zhang");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from users"); %>
<form action="" method="post" />
姓名:<input type="text" name="username"/><br>
学号:<input type="text" name="passwd"/><br>
电话:<input type="text" name="email"/><br>
<input type="submit" value="提交" />
</form>
<form action="index.jsp" method="post">
<input type="submit" value="返回"/>
</form>
本人是小白,所以希望能够写得明白一点儿,最好是能把程序帮忙写出来。。。 展开
展开全部
2个jsp
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<form action="add.jsp" method="post" />
姓名:<input type="text" name="username"/><br>
密码:<input type="text" name="passwd"/><br>
电话:<input type="text" name="email"/><br>
<input type="submit" name="提交">
</form>
</body>
</html>
add.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
</head>
<body>
<%
String name = request.getParameter("username");
String paswd = request.getParameter("passwd");
String email = request.getParameter("email");
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
Connection conn= DriverManager.getConnection(url,"TEST","zhang");
Statement stmt=conn.createStatement();
boolean flag = stmt.execute("insert into users(username,passwd,email) values('"+name+"','"+paswd+"','"+email+"'");
if(flag){
%>
插入数据库成功,数据信息如下
<%=name%><br>
<%=paswd%><br>
<%=email%><br>
<%
}else{
%>
插入数据库失败,请检查数据库连接。
<%
}
%>
</body>
</html>
我这没数据库,你自己测试下。有问题自己调试下。
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<form action="add.jsp" method="post" />
姓名:<input type="text" name="username"/><br>
密码:<input type="text" name="passwd"/><br>
电话:<input type="text" name="email"/><br>
<input type="submit" name="提交">
</form>
</body>
</html>
add.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
</head>
<body>
<%
String name = request.getParameter("username");
String paswd = request.getParameter("passwd");
String email = request.getParameter("email");
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
Connection conn= DriverManager.getConnection(url,"TEST","zhang");
Statement stmt=conn.createStatement();
boolean flag = stmt.execute("insert into users(username,passwd,email) values('"+name+"','"+paswd+"','"+email+"'");
if(flag){
%>
插入数据库成功,数据信息如下
<%=name%><br>
<%=paswd%><br>
<%=email%><br>
<%
}else{
%>
插入数据库失败,请检查数据库连接。
<%
}
%>
</body>
</html>
我这没数据库,你自己测试下。有问题自己调试下。
展开全部
首先你的form太多了,submit提交的是你下面的form,根本不可能传到后台,在后台写一个javabean,里面的属性有username,passwd,email,然后连接数据库,插入数据就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询