Avatar billede ndoem Nybegynder
30. august 2005 - 21:55 Der er 3 kommentarer

Hvorfor får jeg siden kan ikke vises

package mypackage;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class resultater extends HttpServlet {   
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {       
  show(response.getWriter()); 
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException
  {
  try
  {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/hsf");   
    Statement stmt = con.createStatement();
    String name = request.getParameter("name");
    String klasse = request.getParameter("class"); 
    String point = request.getParameter("point");
      stmt.executeUpdate("INSERT INTO resultat(name,class,point) " +
                        "VALUES ('" + name + "','" + klasse + "','" + point + "')");
      stmt.close();
      con.close();   
    }
    catch (ClassNotFoundException e) { 
    throw new ServletException(e.getMessage()); 
    }
    catch (SQLException e) { 
    throw new ServletException(e.getMessage());
    } 
    show(response.getWriter()); 
    } 
      private void show(PrintWriter out) throws ServletException
      {
        out.println("<!doctype html public '-//w3c/dtd HTML 4.01 Transitional//en'>");
        out.println("<html>"); 
        out.println("<head>");
        out.println("<title>Resultater</title>"); 
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Resultater</h1>");
        out.println("<h2>Eksisterende resultater:</h2>"); 
        out.println("<table border>");
        out.println("<tr>"); 
        out.println("<th>Navn</th>"); 
        out.println("<th>Klasse</th>");
        out.println("<th>Point</th>");
        out.println("</tr>"); 
        try {         
          Class.forName("com.mysql.jdbc.Driver");
          Connection con = DriverManager.getConnection("jdbc:mysql://localhost/hsf");
          Statement stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery("SELECT name,class,point FROM resultat");
            while(rs.next()) {
            out.println("<tr>"); 
            out.println("<td>" + rs.getString("name") + "</td>");
            out.println("<td>" + rs.getString("klasse") + "</td>");   
            out.println("<td>" + rs.getInt("point") + "</td>"); 
            out.println("</tr>"); 
            }
              rs.close(); 
              stmt.close();
              con.close();
          } catch (ClassNotFoundException e) {
          throw new ServletException(e.getMessage());        }
          catch (SQLException e) {         
          throw new ServletException(e.getMessage());        }
          out.println("</table>");
          out.println("<h2>Tilføj resultater:</h2>");
          out.println("<form method='post' action='resultater'>");
          out.println("Navn: <input type='text' name='name' size='40'>");
          out.println("<br>");
          out.println("Klasse: <input type='text' name='klasse' size='20'>"); 
          out.println("<br>");
          out.println("Point: <input type='text' name='point' size='40'>"); 
          out.println("<br>"); 
          out.println("<input type='submit' value='Tilføj'>");
          out.println("</form>");
          out.println("</body>");
          out.println("</html>");
          }
}
Avatar billede arne_v Ekspert
30. august 2005 - 22:09 #1
får du nogen fejl i Tomcat (eller den servlet engine du nu bruger) ?

hvordan ligger filerne i din web app ?

hvordan ser web.xml ud ?
Avatar billede ndoem Nybegynder
31. august 2005 - 11:04 #2
Nej jeg får ikke nogen fejl i min servlet engine.
Avatar billede ndoem Nybegynder
31. august 2005 - 19:12 #3
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
  <description>Empty web.xml file for Web Application</description>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>resultater</servlet-name>
    <servlet-class>mypackage.resultater</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Servlet1</servlet-name>
    <servlet-class>mypackage.Servlet1</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>35</session-timeout>
  </session-config>
  <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html</mime-type>
  </mime-mapping>
  <mime-mapping>
    <extension>txt</extension>
    <mime-type>text/plain</mime-type>
  </mime-mapping>
</web-app>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester