求助:新闻发布系统的问题(搞了半天也不知道是哪里出问题了)

wode421898419 2007-03-04 10:46:40
//插入二级标题
<%@ 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,明明插入一级标题的代码和插入二级标题的代码差不多呀,还有一个不理解的地方是一级标题插入后要重新编译,才会在插入二级标题的下拉列表中出现一级标题
...全文
410 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xin678518 2011-12-08
  • 打赏
  • 举报
回复
给我也发个529671930@qq.com
wode421898419 2007-03-06
  • 打赏
  • 举报
回复
上面是哪里错了呀,知道的说一下
zhanglijia 2007-03-06
  • 打赏
  • 举报
回复
也给我发一个,谢谢
zhanglijiapz@163.com
olifeo 2007-03-06
  • 打赏
  • 举报
回复
留个油箱
灌油
dr_lou 2007-03-05
  • 打赏
  • 举报
回复
..
pozhong 2007-03-04
  • 打赏
  • 举报
回复
也给我发一个,谢谢
pozhong@163.com
wode421898419 2007-03-04
  • 打赏
  • 举报
回复
jbuilder2006_3@sina.com
dr_lou 2007-03-04
  • 打赏
  • 举报
回复
给你发个我做的

留个油箱
  • 打赏
  • 举报
回复
还有一个不理解的地方是一级标题插入后要重新编译,才会在插入二级标题的下拉列表中出现一级标题
-------------
这个好说,因为你不重新编译,默认还是会使用上次产生的CLASS文件,除非你把原来的CLASS文件删除,这样应该会自动重编译了。

至于一级和二级的问题,我现在在外面上网,不便细看。留给有时间的朋友帮你解决吧

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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