Okay first of all to introduce myself!
My name is Kostas, I live in Greece and I am in the final semester in the Computer Science departement of Pireaus University(Strange name isn't it?, Pireaus is the largest port in Greece and the 3rd biggest worldwide)
Not until recently I got a project for my University which I had to write in
JSP. So far, only have gotten myself into the paths pf PHP, I needed a good reference book for JSP &
Servlets. For my good luck I bought Head First Servlets & JSP. I only write this because I know that one of the founders of the site is one of the writers of the book.
Well to be honest, after seeing so many posts about troubles, I didn't want to bring my troubles here too. But if anyone wants to help I will gladly appreciate it.
-----------------------------------------------------------------------------------------
My main problem is that I am trying to connect a JSP and its servlet. Well the problem is that the JSP doesnt find the Servlet at all. I use GlassFish server v3 and NetBeans
IDE 6.8v (which IMHO is WAAAY better than Eclipse). Here are the exact steps I put myself into
(I will describe all the steps and the minor details so as to diminish any assumptions brom being made)
1.Create the Project
Here I use an external disk drive (F:/) where all my projects are stored in ([12] NetBeans Workspace/) folder.
Okay here goes:
New Project->
Java Web->Web Application
ProjectName: AcidLabs
ProjectLocation: F:\[12] NetBeans Workspace
ProjectFolder: F:\[12] NetBeans Workspace\AcidLabs
No | UseDeticated Folder for Storing libraries
Yes | Set as Main Project
Server: GlassFish v3 Domain
Java EE6 Web
Framewroks: Only JavaServer Faces
(Using the default library and at configuration preferred language is JSP)
2.Creation of JSP
At Web Pages folders I create J_Login.jsp file.
The code is this:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form method="POST" action="/login.serv">
<input type="TEXT" name="I_Login" /> <br>
<input type="SUBMIT" value="Login"/>
</form>
</body>
</html>
</f:view>
3.Creation of Servlet (File->New File->Servlet)
ClassName: S_Login
Project: AcidLabs
Location: Source Packages
Package: com
(next page will be in the deployment descriptor)
The Servlet code is this:
package com;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class S_Login extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String c = request.getParameter("I_Login");
request.setAttribute("resp",c);
RequestDispatcher view = request.getRequestDispatcher("J_Lessons.jsp");
view.forward(request, response);
} finally {
out.close();
}
}
}
The code is doing nothing than forwarding the parameter from J_Login.jsp
4.The other JSP
The JSP that hears from the servlet is this
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
${param.resp}
</body>
</html>
5. The web.xml
In my web.xml the following 2 structs exist
<servlet>
<servlet-name>CustomServlet</servlet-name>
<servlet-class>com.S_Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CustomServlet</servlet-name>
<url-pattern>/login.serv</url-pattern>
</servlet-mapping>
Running the J_Login.jsp executes the page fine and on submit I get this error
HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.
GlassFish v3
if i call the servlet on the form element by simple "login.serv" without the "/" I get this error which is even worse
HTTP Status 404 - /login.serv not found
type Status report
message/login.serv not found
descriptionThe requested resource (/login.serv not found) is not available.
GlassFish v3
and the servlet is not even found....
I know the servlet is not compiled but I did a previous project experimenting with OpenFaces 2.0 and everything worked fine by the same steps. I wanted to do a fresh start and now I get all these.
Sorry to trouble you. Any help will be much appreciated!!!
