求助:新闻发布系统的问题(搞了半天也不知道是哪里出问题了)
//插入二级标题
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.ArrayList,news.FirstLevelTitle,news.FirstLevelTitleDAO" %>
<%!
FirstLevelTitleDAO fd=new FirstLevelTitleDAO();
FirstLevelTitle ft=new FirstLevelTitle();
ArrayList list1=fd.show1();
%>
<table width="760" border="1" cellspacing="0" cellpadding="0" align="center">
<tr>
<td height="140" colspan="2"><img src="pic/321.jpg" width="760" height="140" alt=""></td>
</tr>
<tr>
<td width="210" height="400" valign="top"><br><b> 新闻发布后台管理</b>
<br> <a href="FirstTitle.jsp">一级标题发布</a>
<br> 二级标题及文件位置发布</td>
<td width="550" height="400">
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><center><b><center>二级标题及文件位置发布</center></b><br><br>
<form method="post" action="secondinsert">
<table><tr><td>一级标题:</td><td>
<select name="first">
<%
for(int i=0;i<list1.size();i++){
ft=(FirstLevelTitle)list1.get(i);
%>
<option value="<%=ft.getTitleName()%>"><%=ft.getTitleName()%></option>
<%}
%>
</select></td></tr>
<tr><td>二级标题:</td><td><input type="text" name="secondname"></td></tr>
<tr><td>文件位置:</td><td><input type="file" name="filepath"></td></tr>
<tr><td></td><td><input type="submit" value="确定"><input type="reset" value="重置"></td></tr>
</table>
</form>
<br>(二级标题最好与新闻稿件标题一致)
<br><br><b>注意:发布前请认真检查输入的内容是否正确。</b>
</center></td>
</tr>
</table>
</td>
</tr>
</table>
package news;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
public class SecondInsert extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GBK");
String first=request.getParameter("first");
String secondname=request.getParameter("secondname");
String filepath=request.getParameter("filepath");
Connection con=null;
Statement st=null;
ResultSet rs=null;
if(first!=null&&!first.equals("")&&secondname!=null&&!secondname.equals("")&&filepath!=null&&!filepath.equals("")){
con=DBConnection.getCon();
try {
st = con.createStatement();
rs = st.executeQuery(
"select * from SecondLevelTitle where titlename='" +
secondname + "'");
if (!rs.next()) {
st.executeUpdate("insert into SecondLevelTitle values ('" +
secondname + "','" +
filepath + "',default,'" + first + "'");
out.print("<font color='red'>二级标题及文件位置发布成功!</font>");
} else {
out.print("<font color='red'>不能重复发布同一标题!</font>");
}
} catch (SQLException ex) {
ex.toString();
}
try {
rs.close();
st.close();
con.close();
} catch (SQLException ex1) {
ex1.printStackTrace();
out.print("一级标题:" + first);
out.print("<br>二级标题:" + secondname);
out.print("<br>文件位置:" + filepath);
}
}else{
out.print("<font color='red'>请填写完整!</font>");
out.print("<br>一级标题:"+first);/*这里打印的first,secondname和filepath都为空(?)*/
out.print("<br>二级标题:"+secondname);
out.print("<br>文件位置:"+filepath);
}
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
不知道为什么,一级标题可以插入,二级标题总是得到null,明明插入一级标题的代码和插入二级标题的代码差不多呀,还有一个不理解的地方是一级标题插入后要重新编译,才会在插入二级标题的下拉列表中出现一级标题