请各位大侠帮忙改下!
我的JSP代码是这样的:
<%@ page language= "java " contentType= "text/html; charset=GB2312 "
pageEncoding= "GB2312 "%>
<%@ page import= "java.util.* "%>
<%@ page import= "java.sql.* "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GB2312 ">
<title> FX订饭 </title>
</head>
<body>
<h2> 订饭喽 </h2>
<form name= "form1 " method= "post " action= "Ex5_2.jsp?action=submit ">
<table width= "59% " height= "156 " border= "0 " cellpadding= "0 "
cellspacing= "0 ">
<tr>
<td width= "21% "> 姓名: </td>
<td width= "79% "> <input name= "name " type= "text " size= "10 "> </td>
<br>
<P> 今日菜谱:
<br>
<input type= "radio " name= "meal " value= "茄子 "> 茄子
<input type= "radio " name= "meal " value= "鸡丁 "> 鸡丁
<input type= "radio " name= "meal " value= "肉燥 "> 肉燥
<input type= "radio " name= "meal " value= "排骨 "> 排骨
<br>
<tr>
<td> </td>
<td> <input type= "submit " name= "Submit " value= "添加 "> </td>
</tr>
</table>
</form>
<font size=2>
<%//连接需要的对象
Connection conn = null;
Statement stmt = null;
String sql = null;
ResultSet rs = null;
int ret;
String action = request.getParameter( "action ");
if ( "submit ".equals(action)) {
String name = request.getParameter( "name ");
String meal = request.getParameter( "meal ");
Timestamp addtime = new Timestamp(System.currentTimeMillis());
try {
Class.forName( "com.mysql.jdbc.Driver "); //载入JDBC驱动程序
String strCon = "jdbc:mysql://localhost:3306/JspSamples "; //连接字
conn = DriverManager.getConnection(strCon, "root ", "123456 "); //连接数据库
stmt = conn.createStatement(); //初始化查询
sql = "insert into customers (Name, meal,) values( ' "//插入数据
+ name + " ', ' " + meal + " ', ' " + addtime + " ') ";
ret = stmt.executeUpdate(sql);//执行插入数据
stmt.close();//关闭查询
conn.close();//关闭连接
} catch (ClassNotFoundException e) { //意外处理,驱动程序无法找到
e.printStackTrace();
out.println( " <h1> 无法找到数据库驱动 </h1> ");
} catch (SQLException e1) { //意外处理,数据库操作失败
e1.printStackTrace();
out.println( " <h1> 数据库操作失败 </h1> ");
}
out.println( " <h1> 插入数据到JspSamples的customers表成功 </h1> ");
}
%> </font>
</body>
</html>
我要把他改成struts类型的 一个action调用jsp,请各位大侠帮忙改下!谢了!
[解决办法]
整个框架必须先搭好的,这么改不如重新写一个~~~