提交表单问题,

aaaabbbccd9876 2012-10-17 11:04:14
  <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去实现,求助啊
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
最美的词 2012-10-18
  • 打赏
  • 举报
回复
1.在form里面,提交的那个按钮不是button类型,而是submit类型,2楼说的是对的;
2.你的sql语句写错了,语法错误,正确写法4楼给出了
omghaa 2012-10-18
  • 打赏
  • 举报
回复
2楼正解。

insert语句是这样的。

insert into tableName values(val1,val2,val3....);
cscript 2012-10-17
  • 打赏
  • 举报
回复
首先你的表单没提交
<input type="button" name="Submit" value="提交" />
改成
<input type="submit" name="Submit" value="提交" />

然后你的 insert * from 是什么东西?

提交后 根据 jsp的异常信息 慢慢调试吧
wei2253498 2012-10-17
  • 打赏
  • 举报
回复
建议你还是学学servlet吧
丨深水蓝丨 2012-10-17
  • 打赏
  • 举报
回复
楼上正解

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧