Witam,
Zaczynam przygodę z JavaEE, zakupiłem sobie książkę Java EE 6 Programowanie aplikacji WWW, żeby od czegoś zacząć, niestety zakłada ona programowanie w NetBeans. Ten kod wygenerowałem w Eclipsie, nie wiem czy to po tej stronie może leżeć jakiś błąd ?
Formularz wyświetla się ładnie, podajemy swoje imię, niestety klikając przycisk submit ("OK") otwiera się pusta strona internetowa ;/
Będę wdzięczny za pomoc.
plik index.jsp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World!</h1>
<form action="Hello.do">
<input type="text" name="imie" />
<input type="submit" value="OK" />
</form>
</body>
</html>
Servlet:
package pl.helion.jeeweb.HelloServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html:charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String login = request.getParameter("imie");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet HelloWorld</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Witaj, " + login + ", na tym swiecie! </h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
public HelloServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
plik web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>pl.helion.jeeweb.HelloServlet.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/Hello.do</url-pattern>
</servlet-mapping>
</web-app>