import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.StringTokenizer; import java.sql.*; public class news extends HttpServlet { public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException { vastus.setContentType("text/html"); PrintWriter valja = vastus.getWriter(); valja.println(""+ "Sisestus\n"+ "
"+ ""); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection( "jdbc:odbc:andmebaas", "", ""); Statement st=cn.createStatement(); String fdata=kysimus.getParameter("data"); if (fdata != null){ // Lisa teema String ftopic=kysimus.getParameter("topic"); if(!ftopic.equals("") && fdata.equals("true")) { String lause="INSERT INTO news_topics values ('', '"+ftopic+"');"; st.executeUpdate(lause); } // Lisa uudis String fnews=kysimus.getParameter("news"); String fnews_title=kysimus.getParameter("news_title"); String fnews_topic=kysimus.getParameter("news_topic"); if(!fnews.equals("") && fdata.equals("true")) { String lause="INSERT INTO news_entries values ('', '"+fnews_topic+"', '"+fnews+"', '"+fnews_title+"');"; st.executeUpdate(lause); } // Lisa kommentaar String fcomment=kysimus.getParameter("comment"); String fnewsEntry=kysimus.getParameter("newsEntry"); String femail=kysimus.getParameter("email"); if(!fcomment.equals("") && fdata.equals("true")) { String lause="INSERT INTO news_comments values ('', '"+fnewsEntry+"', '"+fcomment+"', '"+femail+"');"; st.executeUpdate(lause); } } valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println("
"); // // LISAMISED // valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println(""); valja.println("
Add topic
Topic
Add news
Title
Choose topic"); valja.println(""); valja.println("
Add comment
Choose news"); valja.println(""); valja.println("
E-mail
"); valja.println("
"); // // UUDISED // String ftopic=kysimus.getParameter("topic"); String fcomment=kysimus.getParameter("comments"); if (ftopic != null && fcomment == null) { lause="SELECT * FROM news_entries where topic_id = '"+ftopic+"' order by title"; rs=st.executeQuery(lause); while(rs.next()) { valja.println("

"+rs.getString("title")+"

"+rs.getString("news")+"

Comments"); } valja.println("

Back"); } if (ftopic == null && fcomment == null) { lause="SELECT * FROM news_topics order by topic"; rs=st.executeQuery(lause); while(rs.next()) { valja.println("

"+ rs.getString("topic")+"

"); } } String epost; if (fcomment != null && ftopic != null) { lause="SELECT * FROM news_comments where entry_id = '"+fcomment+"' order by 'id'"; rs=st.executeQuery(lause); while(rs.next()) { epost = rs.getString("email"); valja.println(""+epost+"
"+rs.getString("comment")+"

"); } valja.println("
Back"); } valja.println("
"); valja.println(""); cn.close(); } catch(Exception viga) { viga.printStackTrace(valja); } //<--- //valja.println(""); } }