<body>
<form id="form1" name="form1" method="post" action="saveArtical.jsp">
<table width="795" border="0" cellspacing="0" cellpadding="0" height="280">
<tr>
<td align="center">文章标题:</td>
<td><input name="articaltitle" type="text" id="articaltitle" /><font color="red">请不要以数字开头</font></td>
</tr>
<tr>
<td align="center">文章内容:</td>
<td>
<textarea id="content1" name="content1" rows="55" cols="55" ></textarea>
</tr>
<tr>
<td><input type="button" name="Submit" value="提交" />
<input type="button" name="reset"value="重填" />
</td></tr>
</table>
</form> <%String driverName="com.mysql.jdbc.Driver";//数据库用户名String userName="root";//密码String userPasswd="1";//数据库名String dbName="test";
String sql=null;
Statement statement;
//表名String tableName="wenzheng";//联结字符串
request.setCharacterEncoding("utf-8");
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
try{
Class.forName(driverName); Connection connection=DriverManager.getConnection(url); statement= connection.createStatement();
String articaltitle=request.getParameter("articaltitle");
String content1=request.getParameter("content1");
sql="insert * from "+tableName+"values('" + content1+ "','" + articaltitle+ "')";
//out.println(user+"..."+pwd);('" + content1+ "','" + articaltitle+ "')
String Submit=request.getParameter("Submit");
String reset=request.getParameter("reset");
out.println(articaltitle+"...."+content1+"...."+Submit);
if(Submit.equals("提交"))
statement.executeUpdate(sql);
statement.close();
connection.close();
}
catch(Exception e){} %>我想把表单里面的内容提交到mysql数据库,这样实现不了,怎么去实现啊,本人不会servlet和javaBean,用jsp去实现,求助啊
<form id="form1" name="form1" method="post" action="saveArtical.jsp">
<table width="795" border="0" cellspacing="0" cellpadding="0" height="280">
<tr>
<td align="center">文章标题:</td>
<td><input name="articaltitle" type="text" id="articaltitle" /><font color="red">请不要以数字开头</font></td>
</tr>
<tr>
<td align="center">文章内容:</td>
<td>
<textarea id="content1" name="content1" rows="55" cols="55" ></textarea>
</tr>
<tr>
<td><input type="button" name="Submit" value="提交" />
<input type="button" name="reset"value="重填" />
</td></tr>
</table>
</form> <%String driverName="com.mysql.jdbc.Driver";//数据库用户名String userName="root";//密码String userPasswd="1";//数据库名String dbName="test";
String sql=null;
Statement statement;
//表名String tableName="wenzheng";//联结字符串
request.setCharacterEncoding("utf-8");
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
try{
Class.forName(driverName); Connection connection=DriverManager.getConnection(url); statement= connection.createStatement();
String articaltitle=request.getParameter("articaltitle");
String content1=request.getParameter("content1");
sql="insert * from "+tableName+"values('" + content1+ "','" + articaltitle+ "')";
//out.println(user+"..."+pwd);('" + content1+ "','" + articaltitle+ "')
String Submit=request.getParameter("Submit");
String reset=request.getParameter("reset");
out.println(articaltitle+"...."+content1+"...."+Submit);
if(Submit.equals("提交"))
statement.executeUpdate(sql);
statement.close();
connection.close();
}
catch(Exception e){} %>我想把表单里面的内容提交到mysql数据库,这样实现不了,怎么去实现啊,本人不会servlet和javaBean,用jsp去实现,求助啊
解决方案 »
- 关于内存数据库
- 求:任意输入一个算式就能计算出结果的四则混合运算很急(java)
- Struts2 <jsp:forwoard /> 不能跳转
- JBuilder 2008 为什么不能创建web项目
- html标签库不能用
- JAVA连接数据库的存储过程没有异常,但是为什么就是执行不了呢?求大神解决。
- 为什么ImageIO.write(image, "JPEG", response.getOutputStream())在weblogic7.0里用不了
- xml 流化时出现的权限问题?
- 帮帮忙,一个新手的问题
- Android开发AVD新建问题
- 我做了一个自动发邮件,发出的主题全是null,怎样解决?
- 在线求助怎么解决这个浏览器不兼容问题
<input type="button" name="Submit" value="提交" />
改成
<input type="submit" name="Submit" value="提交" />然后你的 insert * from 是什么东西?提交后 根据 jsp的异常信息 慢慢调试吧
2.你的sql语句写错了,语法错误,正确写法4楼给出了