How to know which servlet and JSP version am I using? - java

Can you tell me how to know which servlet and JSP version am I using ?
I use NetBeans IDE 7.1.2 for creating Servlets and JSP.

You can easily check the JSP,SERVER and SERVLET version. Add the following code in your jsp page after that run using any IDE Tools.
Server Version: <%= application.getServerInfo() %><br>
Servlet Version: <%= application.getMajorVersion() %>.<%= application.getMinorVersion() %>
JSP Version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %> <br>

You can get the details programatically using ServletContext #getMajorVersion() and #getMinorVersion().
For knowing the JSP version corresponding to the Servlet, you can get details from this Tomcat page.
Below is a brief summary (check Tomcat's corresponding version at the link above):
Servlet 4.0 uses JSP 2.3
Servlet 3.1 uses JSP 2.3
Servlet 2.5 uses JSP 2.1
Servlet 2.4 uses JSP 2.0
Servlet 2.3 uses JSP 1.2
Servlet 2.2 uses JSP 1.1
Servlet 2.1 uses JSP 1.0

The version is declared in the web.xml file using the attribute version.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
...
</web-app>
Read more

Related

Spring MVC Restful Application error 404. Why? [duplicate]

This question already has answers here:
Servlet 5.0 JAR throws compile error on javax.servlet.* but Servlet 4.0 JAR does not
(3 answers)
Closed 1 year ago.
I'm having a problem with my first Web Application. I use IntelliJ as IDE and Tomcat as Webserver.
Every servlet I've tried to acces, throws an 404 Error. Even if I copy some youtube tutorials, which seems to work like a charm.
The button in the form sends me to: http://localhost:8080/IUBHQuiz/login
Can you tell me whats wrong? I am going nuts.
login.java
package com.example.IUBHQuiz;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.sql.*;
#WebServlet("/login")
public class login extends HttpServlet {
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String email = request.getParameter("fmail");
String pass = request.getParameter("fpw");
if(email.equals("j") && pass.equals("j"))
{
RequestDispatcher rs = request.getRequestDispatcher("/main.jsp");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("/index.jsp");
rs.include(request, response);
}
out.close();
}
index.jsp
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>IUBH Quiz</title>
<link href="./resources/css/style.css" rel="stylesheet">
</head>
<body>
<div class="main">
<div class="image-container">
<img src="./resources/images/logo.png" alt="Logo">
</div>
<div class="Login">
<h1>Willkommen beim IUBH-Quiz!</h1>
<form action="login" method="post">
E-Mail:<input type="text" id="fmail" name="fmail"><br><br>
Passwort: <input type="password" id="fpw" name="fpw"><br><br>
<input type="submit" value="Log In" class="button">
</form>
</div>
<div class="Links">
Passwort vergessen
Registrieren
</div>
</div>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>
For copyright reasons the Servlet 5.0 API (implemented by Tomcat 10) and the Servlet 4.0 API (implemented by Tomcat 9) are incompatible: the API namespace changed from javax.* to jakarta.*. This can manifest in many ways:
Software written for Servlet 4.0 does not compile against the API jars from Tomcat 10: cf. Servlet 5.0 JAR throws compile error on javax.servlet.* but Servlet 4.0 JAR does not,
Servlet 4.0 applications which use a web.xml descriptor throw a lot of ClassNotFoundExceptions and don't start: cf. Tomcat 10.x throws java.lang.NoClassDefFoundError on javax/servlet/ServletRequestListener.
Servlet 4.0 applications which use a web.xml descriptor log a "X is not a jakarta.servlet.Servlet" error: cf. Servlet class org.restlet.ext.servlet.ServerServlet is not a jakarta.servlet.Servlet.
Servlet 4.0 applications which use annotations to declare servlets stop working, as in your case,
Servlet 4.0 applications which rely on a ServletContainerInitializer (like Spring and Spring Boot applications) don't start: cf. Deploying Spring MVC 5 on Tomcat 10 … deployment problems
The last one is the hardest to diagnose: no errors are written to the log files, but the application doesn't work. The reason behind this behavior is that #javax.servlet.WebServlet annotations are ignored: the server is scanning for #jakarta.servlet.WebServlet.
Since all three problems have the same cause, the solutions provided to the aforementioned questions all work. In this specific case I would advise to use the Tomcat Migration Tool for Jakarta EE.
Remark: The Tomcat download site features a warning, that unfortunately many people don't notice:
Users of Tomcat 10 onwards should be aware that, as a result of the move from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.* to jakarta.*. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.
I had the same issue while reproducing the problem reported at IntelliJ IDEA forums.
It didn't work with Tomcat 10 for the reasons described in the answer by Piotr P. Karwasz, but it works just fine with Tomcat 9.0.44 and earlier versions.

Tomcat 10.0.4 doesn't load servlets (#WebServlet classes) with 404 error [duplicate]

This question already has answers here:
Servlet 5.0 JAR throws compile error on javax.servlet.* but Servlet 4.0 JAR does not
(3 answers)
Closed 1 year ago.
I'm having a problem with my first Web Application. I use IntelliJ as IDE and Tomcat as Webserver.
Every servlet I've tried to acces, throws an 404 Error. Even if I copy some youtube tutorials, which seems to work like a charm.
The button in the form sends me to: http://localhost:8080/IUBHQuiz/login
Can you tell me whats wrong? I am going nuts.
login.java
package com.example.IUBHQuiz;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.sql.*;
#WebServlet("/login")
public class login extends HttpServlet {
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String email = request.getParameter("fmail");
String pass = request.getParameter("fpw");
if(email.equals("j") && pass.equals("j"))
{
RequestDispatcher rs = request.getRequestDispatcher("/main.jsp");
rs.forward(request, response);
}
else
{
out.println("Username or Password incorrect");
RequestDispatcher rs = request.getRequestDispatcher("/index.jsp");
rs.include(request, response);
}
out.close();
}
index.jsp
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>IUBH Quiz</title>
<link href="./resources/css/style.css" rel="stylesheet">
</head>
<body>
<div class="main">
<div class="image-container">
<img src="./resources/images/logo.png" alt="Logo">
</div>
<div class="Login">
<h1>Willkommen beim IUBH-Quiz!</h1>
<form action="login" method="post">
E-Mail:<input type="text" id="fmail" name="fmail"><br><br>
Passwort: <input type="password" id="fpw" name="fpw"><br><br>
<input type="submit" value="Log In" class="button">
</form>
</div>
<div class="Links">
Passwort vergessen
Registrieren
</div>
</div>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>
For copyright reasons the Servlet 5.0 API (implemented by Tomcat 10) and the Servlet 4.0 API (implemented by Tomcat 9) are incompatible: the API namespace changed from javax.* to jakarta.*. This can manifest in many ways:
Software written for Servlet 4.0 does not compile against the API jars from Tomcat 10: cf. Servlet 5.0 JAR throws compile error on javax.servlet.* but Servlet 4.0 JAR does not,
Servlet 4.0 applications which use a web.xml descriptor throw a lot of ClassNotFoundExceptions and don't start: cf. Tomcat 10.x throws java.lang.NoClassDefFoundError on javax/servlet/ServletRequestListener.
Servlet 4.0 applications which use a web.xml descriptor log a "X is not a jakarta.servlet.Servlet" error: cf. Servlet class org.restlet.ext.servlet.ServerServlet is not a jakarta.servlet.Servlet.
Servlet 4.0 applications which use annotations to declare servlets stop working, as in your case,
Servlet 4.0 applications which rely on a ServletContainerInitializer (like Spring and Spring Boot applications) don't start: cf. Deploying Spring MVC 5 on Tomcat 10 … deployment problems
The last one is the hardest to diagnose: no errors are written to the log files, but the application doesn't work. The reason behind this behavior is that #javax.servlet.WebServlet annotations are ignored: the server is scanning for #jakarta.servlet.WebServlet.
Since all three problems have the same cause, the solutions provided to the aforementioned questions all work. In this specific case I would advise to use the Tomcat Migration Tool for Jakarta EE.
Remark: The Tomcat download site features a warning, that unfortunately many people don't notice:
Users of Tomcat 10 onwards should be aware that, as a result of the move from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.* to jakarta.*. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.
I had the same issue while reproducing the problem reported at IntelliJ IDEA forums.
It didn't work with Tomcat 10 for the reasons described in the answer by Piotr P. Karwasz, but it works just fine with Tomcat 9.0.44 and earlier versions.

How to set jstl in Maven Jetty plugin

I made a simple web project. For ease of use, I used a maven jetty plugin and I made several attempts to use the jstl library. In principle, the plugin has a built-in jstl library, and indeed, although I have not explicitly included jstl-1.2.jar, my pages are compiled. The problem occurs when I try to use the functionality of jstl.
Example jsp:
<%# page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<h2>Hello World!</h2>
<c:set var = "salary" scope = "session" value = "${2000*2}"/>
<c:out value = "${salary}"/>
</body>
</html>
Preview:
I tried this approaches:
1)to include the library as a dependancy in my pom.xml -> the same result
2)to include the library in WEB-INF.lib -> the same result
3)to include jstl-1.2.jar as external jar in dependencies -> the same result
I am using NetBeans 8.2
There is no need to include jstl library when you use maven jetty plugin. The problem was in Servlet descriptor which can be configured from web.xml.
This web.xml solve my problem:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>

#WebServlet annotation and GWT RPC

In my GWT project running in glassfishv3, everything is worked properly, but when I change my servlet url patterns mapping from web.xml to #WebServlet annotation inside servlet classes, GWT rpc cand find the servlet!
note that, other usual servlets work with this annotation(WebServlet) and just GWT RPC doesnt work.
what is the reason?
RGDS
Did you set the version number of web-app in the web.xml to the correct servlet version, because this feature is available only since 3.0:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
Ok, I finally got this working but with some caveats. I was able to get it working in Tomcat within Intellij and as a deployed WAR to a Tomcat 7 container.
I was NOT able to get it working in dev-mode without using -noserver. I believe this is because the built-in Jetty server is not JSR315 compatible but have no evidence of this as I've not tried to determine what version of jetty is in the gwt-dev jar.
The trick is you need to fully qualify the path in WebServlet. So if your remote service interface has the relative path of "bar" and your module name (rename-to in gwt.xml) is "foo" then the path you need to set the path of "/foo/bar" in WebServlet and it will work.

Struts <bean:cookie> tag breaks on WebLogic 11gR1

I'm trying to deploy a very simple Struts app on WebLogic 11gR1. The app has one JSP called Welcome.jsp and this JSP contains the following tag :
<bean:cookie name="" id=""/>
The associated taglib is imported at the top of the JSP using the following line :
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
When this tag is inside the JSP, I've the following error :
Welcome.jsp:11:24: javax.servlet.http.Cookie cannot be resolved
<body bgcolor="white"><bean:cookie name="" id=""/>
But when I remove this tag, the Welcome.jsp works just fine.
The JSP includes other tags like :
<bean:message key="welcome.heading"/>
Those tags are working just fine.
And to finish, the ActionServlet of Struts is also working and starting with the app.
I'm guessing that there must be a classloading problem but I don't understand why the Struts ActionServlet is working : javax.servlet.http.Cookie and javax.servlet.http.HttpServlet are declared in the same package.
Maybe, there is a problem with the Oracle implementation of the Cookie class in WebLogic but it is very unlikely.
Thanks.
javax.servlet.http.Cookie is an interface showing the structure that those who are implementing the Servlet API need to implement.
The issue might be with your WebLogic 11gR1 configuration/libary: I'll explain using Tomcat 7.0.
In Tomcat 7.0, under TOMCAT_HOME/lib folder, there's a servlet-api.jar. That jar allows Tomcat to support the Java Servlet API specification (and has Cookie.class included in the directory, under javax/servlet/Cookie).
Your WebLogic 11gR1 must have a Servlet Container library that conforms to the Servlet API (like Tomcat's servlet-api.jar). I never used WebLogic, but if you have a lib folder somewhere (apparently WL_HOME/server/lib), make sure there's a servlet api somewhere (I think weblogic.jar contains servlet api implementations).
Also, please check that you don't have a servlet like library (e.g. servlet-api.jar, eclipse servlet jars, etc.) inside your WAR file as it can conflict with WebLogic's servlet library.

Categories