<%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK" pageEncoding="GBK"%><%@page import="com.ch6.model.StudentInfo,com.ch6.dal.News" %><%StudentInfo info=new StudentInfo();News news=new News();if("add".equals(request.getParameter("action"))){info.setName(request.getParameter("name"));info.setContent(request.getParameter("content"));info.setDate(request.getParameter("date"));info.setNumber(request.getParameter("number"));news.insert(info);} %><div class="rightbar"> <div class="bread"><a href="../index.html">首页</a> >给我留言</div> <div class="contact_nei"> <form id="form1" name="form1" method="post" action="insert.jsp?action=add"><ul> <li><label>第几条新闻:</label><input id="Id" name="Id" type="text" class="yuyue_in" /> </li><li><label>您的称呼:</label><input id="name" name="name" type="text" class="yuyue_in" /> </li><li><label>你的留言:</label><textarea id="content" name="content" cols="" rows="" class="yuyue_te"></textarea> </li><li><label>时间日期:</label><input id="date" name="date" type="text" class="yuyue_in" /> </li><li><label>资讯:</label><input id="number" name="number" type="text" class="yuyue_in" /><li><input name="button" id="button" type="submit" value="提交" class="btn" /> <input name="" type="reset" value="重置" class="btn" /> </li></ul></form>package com.ch6.dal;import java.sql.*;import java.util.ArrayList;import java.util.List;import com.ch6.Conn;import com.ch6.model.StudentInfo;public class News {Conn conn=new Conn();//获取资讯public List<StudentInfo> getList() throws SQLException{List<StudentInfo> list=new ArrayList<StudentInfo>();String testdb="select * from news order by number asc";ResultSet rs=conn.executeQuerry(testdb);while(rs.next()){StudentInfo info=new StudentInfo();info.setId(rs.getInt("Id"));info.setName(rs.getString("name"));info.setContent(rs.getString("content"));info.setDate(rs.getString("date"));info.setNumber(rs.getString("number"));list.add(info);}conn.close();return list;}public int insert(StudentInfo info){String testdb="insert into news(name,content,date,number)values";testdb=testdb+"('"+info.getName()+"','"+info.getContent()+"','"+info.getDate()+"','"+info.getNumber()+"')";int result=0;System.out.println(testdb);result=conn.executeUpdate(testdb);conn.close();return result;}}
添加回答
举报
0/150
提交
取消