I'd like to code my own JavaEE-App. I'm using Linux Mint and Glassfish 4 as an App-Server. My Eclipse is Oxygen (EE-Version).
I'd like to test if my Costumer is able to sign in.
I haven't include CSS yet so it might look a bit boring. :D
These are my projects in Eclipse:
This is my Index-HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<link rel="stylesheet" href="css/styles.css">
<title>Onlineshop</title>
</head>
<body>
<header>
<hgroup>
<h1 class="title">Onlineshop</h1>
</hgroup>
<nav>
<a href="index.html">Home</a>
<a href="register.html">Registrieren</a>
<a href="signin.html">Einloggen</a>
<a href="sell.html">Verkaufen</a>
<a href="search.html">Suchen</a>
</nav>
</header>
<footer>
Copyright
</footer>
</body>
"Registrieren" means "sign up", "Einloggen" means "to log in", "Verkaufen" means "to sell" and "Suchen" means "to search".
This is the HTML-Site which is displayed after clicking on "Registrieren":
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<link rel="stylesheet" href="css/styles.css">
<title>Onlineshop</title>
</head>
<body>
<header>
<hgroup>
<h1 class="title">Onlineshop</h1>
</hgroup>
<nav>
<a href="index.html">Home</a>
<a href="register.html">Registrieren</a>
<a href="signin.html">Einloggen</a>
<a href="sell.html">Verkaufen</a>
<a href="search.html">Suchen</a>
</nav>
</header>
<form action="register" method="post">
<fieldset>
<legend>Registrieren</legend>
<table>
<tbody>
<tr>
<th>
<label for="email">Email:</label>
</th>
<td>
<input
type="email"
name="email"
size="40"
maxlength="40"
title="muster@beispiel.de"
placeholder="E-Mail eingeben"
pattern=".{6,40}"
required="required">
</td>
</tr>
<tr>
<th>
<label for="password">
Password:
</label>
</th>
<td>
<input
type="password"
name="password"
size="10"
maxlength="10"
title="6-10 Zeichen"
placeholder=
"Passwort eingeben"
pattern=".{6,10}"
required="required">
</td>
</tr>
<tr>
<td/><td>
<input type="submit">
<input type="reset">
</td>
</tr>
</tbody>
</table>
</fieldset>
</form>
<footer>
Copyright
</footer>
</body>
This is my Servlet:
package de.java2enterprise.onlineshop;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public RegisterServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
final String email = request.getParameter("email");
final String password = request.getParameter("password");
final PrintWriter out = response.getWriter();
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<body>");
out.println("<br> Ihre Eingaben");
out.println("<br> EMail: " + email);
out.println("<br> EMail: " + password);
out.println("</body>");
out.println("</html>");
}
}
I didn't write an Web.xml because i just want to cope it with annotations. Now I have 2 questions:
All the imports of the Servlet-API can't be resolved. But why? I did create a Java-Enterprise-Application-Project and assigned the Webproject onlineshop-war to the App. And the Glassfish is assigned to the Java-Enterprise-Application-Project and on the Glassfish-Server is the Servlet-API recorded, isn't it?
And the Second question: Why can't he find the Servlet after clicking on submit after typing in the EMail and the Password on the register-HTML? Has it something to do with question 1?
Thank you very much!