Hey, bin am Anfang des Buches „JSP Cookbook“ von O’Reilly.
Und habe nun das erste Beispiel erfolgreich kompilliert.
Wie man im Code erkennen kann soll ja eine Form angezeigt werden.
Allerdings weiß ich nun nicht wie und wo die angezeigt wird.
Muss ich vielleicht extra noch eine html-Datei schreiben die auf das servlet zugreift ?
In der Uni benutzen wir „myron“… können dort unsere Sachen hochladen und das Ding kompiliert auch …
wenn ich auf den Link „zum servlet“ klicke kommt aber nur
„The server encountered an internal error () that prevented it from fulfilling this request.“
Kann mir irgendjemand weiterhelfen ???
Ich habe alle "
Der Code sieht wie folgt aus:
package com.jspservletcookbook;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
System.out.println("command: "+request.getParameter("command"));
//set the MIME type of the response, "text/html"
response.setContentType("text/html");
//use a PrintWriter send text data to the client who has requested the servlet
java.io.PrintWriter out = response.getWriter();
//Begin assembling the HTML content
out.println("");
out.println("Help Page");
out.println("Please submit your information");
//make sure method="post" so that the servlet service method
//calls doPost in the response to this form submit
out.println(
"");
out.println("");
out.println("Your first name: ");
out.println("");
out.println("");
out.println("Your last name: ");
out.println("");
out.println("");
out.println("Your email: ");
out.println("");
out.println("");
out.println("");
out.println("");
out.println("");
} //end doGet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,java.io.IOException{
//display the parameter names and values
Enumeration paramNames = request.getParameterNames();
String parName;//this will hold the name of the parameter from the HTML form
boolean emptyEnum = false;
if (! paramNames.hasMoreElements())
emptyEnum = true;
//set the MIME type of the response, "text/html"
response.setContentType("text/html");
//use a PrintWriter send text data to the client who has requested the servlet
java.io.PrintWriter out = response.getWriter();
//Begin assembling the HTML content
out.println("");
out.println("Submitted Parameters");
if (emptyEnum){
out.println("Sorry, the request does not contain any parameters");
} else {
out.println("Here are the submitted parameter values");
}
while(paramNames.hasMoreElements()){
parName = (String) paramNames.nextElement();
out.println("" + parName + " : " + request.getParameter(parName));
out.println("");
}//while
out.println("");
}// doPost
}
Danke im voraus !!