I am getting the error on importing a class located in a subpackage in JSP.
Effective code of index.jsp:
<%# page import="a.b.TestDetails" contentType="text/html"
pageEncoding="UTF-8" errorPage="Error/error-page.jsp"%>
Error i am recieving:
HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
GlassFish Server Open Source Edition 4.0
When i remove the import page loads correctly but when i use it to import class, it gives me above error.
try :
<%# page import="a.b.TestDetails" %>
// here a.b is package & sub-package name & TestDetails llbe name of Class which you want to import.
remove contentType="text/html" & other code.
Then test it again, if still problem post me.
Related
I've encoutered some problems with using tomcat.For some reason tomcat can't load my stylesheet.The link is defined inside the head.jsp,this file i include using the include directive in all my jsps that need the stylesheet.I found out that this problem occurs when i dispatch from Servlet to Jsp using the request.getRequestDispatcher(...).When i accessed the same file directly,the stylesheet loads normally.
Image1:
Image2:
Image3:
Image4:
You are missing context path of project.
Case 1: Consider your current URL is http://localhost:8585/project_name/
Then including stylesheet with` ``href = "css/style.css"```
==> http://localhost:8585/project_name/css/style.css
Case 2: Consider your current URL is http://localhost:8585/project_name/users
Then including stylesheet with` ``href = "css/style.css"```
==> http://localhost:8585/project_name/users/css/style.css
404 error
So use context path as prefix, To use context path while including javascript or stylesheet use JSTL tag library and url tag to achieve it as given below.
Include JSTL
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Include stylesheet or scripts by using jstl url tag as given below
<link rel="stylesheet" href="/css/style.css" />" >
I don't know what I've done incorrectly, but I can't include JSTL. I have jstl-1.2.zip, taglibs-standard-jstlel-1.2.5.zip in my WEB-INF/lib but unfortunately I get exception:
jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
I included also the taglib : <%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> in my JSP file. Please help me I couldn't find a solution for this problem, I just want to show hello world with the jstl technology so i can go and learn more about it.
MyservletMyJSPFile
Learning JSP and have an issue with the css/js content not loading. I have a jsp page, where I have bootstrap css and js referenced using standard html link and script tags:
<link rel="stylesheet" type="text/css" link="/bootstrap/css/bootstrap.css" />
and
<script src="/WebIntro/bootstrap/js/bootstrap.js"></script>
neither of them work and Chrome is giving me the following on the console:
Resource interpreted as Stylesheet but transferred with MIME type text/plain:
If I use an include directive, it works for the css but pulls all the content into the file:
<%#include file="/bootstrap/css/bootstrap.css"%>
The jsp has the following #page and meta tags:
<%#page contentType="text/html" %>
and
<meta http-equiv = "Content-Language" content = "en"/>
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
I tried googling and found the mime-mapping element for the web.xml but the following seems to have no affect:
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>
If there is some standard Tomcat config that needs to happen I am unaware as I am new to Tomcat; using Tomcat 7, and eclipse and this is in a maven project.
The solution for me was very strange. The changes to the web.xml file that was present since I built the project in eclipse/maven, weren't reflected in the web.xml within tomcat webapp application directories. Everything else in the package updates fine (as far as I can tell), except for the web.xml?
So I found the web.xml file within eclipse inside target >> project-SNAPSHOT >> WEB-INF >> web.xml (which is supposed to be derived). Forced changes there and it worked, changes were picked up and my original issue gone.
I am guessing I had inadvertently broken some type of dependency link or something along the way somehow, but once I added the servlet, mappings, etc back in, everything worked fine.
Weird.
Removing this line in jsp resolved the error for us.
We were facing the issue when using Tomcat 8.5.59
I have created an EE project in MyEclipse.
I have one jsp file under "WebRoot" and it contains the following lines:
<%# page language="java" import="java.util.*,java.sql.*,com.sp.model.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
String username=request.getParameter("username");
String password=request.getParameter("passwd");
UserBeanCL ubc=new UserBeanCL();
%>
...
and I have also created a package called com.sp.model under "src" in MyEclipse.As you can see from the first line of the JSP code above, I have imported that package using import statement.UserBeanCL is just a normal JAVA class sits under that package, nothing special. Everything looks good in MyEclipse.It does find the package and the UserBeanCL class.
However, after I deployed the whole site into Tomcat and try run this JSP in browser, it always gives error and complains about line:
UserBeanCL ubc=new UserBeanCL();
The error is like: "UserBeanCL cannot be resolved to a type". The stacktrace is:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
This error is confusing to me, since it only appears after deployment. Could experts help me on where to debug? Thanks in advance.
Use:
<%# page language="java" import="java.util.*,java.sql.*,com.sp.model.*" pageEncoding="ISO-8859-1"%>
Regards;
The editor in MyEclipse will usually create separate import statements for each type, if you let it. That is, the following statement would be added, in your case:
<%page import="com.sp.model.UserBeanCL">
I'm not sure that this will help as I couldn't replicate your problem, but it might help if there are more messages in your console than you posted, as the primary cause may be some parsing problem, which would show up in earlier console messages.
I am trying to include 2 JSP files in my JSP page. My main page is called temp.jsp - this is in a subfolder in my web project called tempFolder.
I am trying to include a file in the main project folder (called invalidcqs.jsp) and a file (called env_status_report.jsp) in a sub folder (envmon) of the main project folder.
the code in my temp.jsp file is:
<html>
<head>
<title>Screen1 using includes</title>
<meta http-equiv="refresh" content="10"/>
</head>
<body style="background-color:#E6E6FA">
<%# include file="../envmon/env_status_report.jsp" %>
<br><hr><br>
<%# include file="../invalidcqs.jsp" %>
</body>
</html
The second include <%# include file="../invalidcqs.jsp" %> works fine but the first one <%# include file="/../envmon/env_status_report.jsp" %> shows an error in Eclipse.
The text of the error is:
Multiple annotations found at this line:
- Syntax error on token "else", delete this token
- Syntax error, insert "Finally" to complete
TryStatement
- Syntax error on token "else", delete this token
Does anyone know why Eclipse doesn't like this?
Usually I don't care much about Eclipse reporting errors on jsp pages, specially when using the <%# include> directive. For instance, if you declare a scriptlet variable in your main page and use it in the included page, Eclipse will complain about it not being declared while in the included page, but it will work all right at runtime.
This error is possibly coming out of the included jsp, so I'd start looking for this error inside it.
You could also try to include pages the EL way:
<jsp:include page="/WEB-INF/pages/received.shtml" />
Maybe that will help