har 2 submit knapper hvis jeg udkommentere den ene i min Servlet virker det fint
Men hvis prøver at adskille koden i min servlet får jeg en null pointer exceptionkode i Servlet
dette fungerer fint
//denne kode henter data fra hmtlside tabellen
if(request.getParameter("hent data").equals("hent data")){
System.out.println("kommer her");
Connection con = null;
int id;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///flex", "root",
"d");
if (!con.isClosed())
System.out.println("Successfully connected to "
+ "MySQL server using TCP/IP...");
String i = request.getParameter("group");
id = new Integer(i).intValue();
PreparedStatement ps = con.prepareStatement("select title,overskrift,tekst from htmlside where id = ?");
ps.setInt(1, id);
ResultSet res = ps.executeQuery();
String title ="";
String overskrift ="";
String tekst = "";
while(res.next()) {
title = res.getString("title");
overskrift = res.getString("overskrift");
tekst = res.getString("tekst");
}
HttpSession ses = request.getSession();
ses.setAttribute("tekst", tekst);
ses.setAttribute("title", title);
ses.setAttribute("overskrift", overskrift);
ses.setAttribute("radioButtonId", id + "");
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if (con != null)
con.close();
} catch (SQLException e) {
}
}//end hent data
response.sendRedirect("controller.jsp");
dette giver nullpoint exception
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
if(request.getParameter("indsend").equals("indsend")) {
System.out.println(true);
response.sendRedirect("controller.jsp");
}
System.out.println(request.getParameter("indsend"));
System.out.println("hent data "+request.getParameter("hent data"));
//denne kode henter data fra hmtlside tabellen
if(request.getParameter("hent data").equals("hent data")){
System.out.println("kommer her");
Connection con = null;
int id;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///flex", "root",
"d");
if (!con.isClosed())
System.out.println("Successfully connected to "
+ "MySQL server using TCP/IP...");
String i = request.getParameter("group");
id = new Integer(i).intValue();
PreparedStatement ps = con.prepareStatement("select title,overskrift,tekst from htmlside where id = ?");
ps.setInt(1, id);
ResultSet res = ps.executeQuery();
String title ="";
String overskrift ="";
String tekst = "";
while(res.next()) {
title = res.getString("title");
overskrift = res.getString("overskrift");
tekst = res.getString("tekst");
}
HttpSession ses = request.getSession();
ses.setAttribute("tekst", tekst);
ses.setAttribute("title", title);
ses.setAttribute("overskrift", overskrift);
ses.setAttribute("radioButtonId", id + "");
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if (con != null)
con.close();
} catch (SQLException e) {
}
}//end hent data
response.sendRedirect("controller.jsp");
}
}