67,512
社区成员
发帖
与我相关
我的任务
分享
<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去实现,求助啊