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
Related
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
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.
After browsing through the whole internet I ended up asking this question, although I find it a bit difficult to describe the situation.
I have a little application here which runs on embedded Tomcat server (v7), and uses servlets and JSPs; I try to internationalize them with JSTL tags. The final project is deployed as JAR, and when I run it from the console with java -jar, the embedded server starts nicely, everything works just fine.
The problem is when I try to run it in the IDE (I use IntelliJ Idea v13.1.2): again, it starts, but instead of the values from the bundle, the pages show values such as ???default.username???.
Here is how my JSPs mostly look like:
<!DOCTYPE html>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%# page contentType="text/html;charset=UTF-8" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="language"
value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}"
scope="session"/>
<fmt:setLocale value="${language}"/>
<fmt:setBundle basename="messages" scope="session" var="bund"/>
<html>
<head>
<title><fmt:message bundle="${bund}" key="default.title" /></title>
<link rel="stylesheet" type="text/css" href="../css/tdb.css" media="all">
</head>
And so on. The <fmt:message bundle="${bund}" key="default.title" /> and similar parts work perfectly fine when I use the JAR, and result in ???default.title??? when from IDE. In one case I use the bundle file from the servlet, and when ran from JAR, it works fine, and when from IDE, it causes java.util.MissingResourceException.
What have I tried so far? I added my messages.properties and messages_en_US.properties files in various locations (in resources folder, on the same level with the java and webapp folders; in separate package in the com.my.example package; as simple properties files in the com.my.example package), tried to refer to it only with the basename (resourceBundle = ResourceBundle.getBundle("messages", locale);), or with the fully qualified path; also, I set the fallbackLocale and localizationContext parameters in the web.xml file.
What am I missing?
Code looks well.
I was checking in some of my projects and I have this attributes:
<fmt:setBundle basename="org.juanitodread.msg.label" var="label"/>
<fmt:message key="common.title" bundle="${label}" />
I have my projects in Eclipse, but you can try without "scope" attribute. My label.properties file is in "org.juanitodread.msg" package.
I also use the Intellij Idea and had the similar problems, here are my conclusions. You should put your 'messages file' to
yourproject/src/main/java/resources
folder (as a rule, Idea will highlight the resources folder icon with the specified sign). I have no fallback locale configuration and localization context parameters in web.xml. My bundle file is named messages_en.properties and I use it the way
<fmt:setBundle basename="messages" var="labels" />
and not add "resources.messages" to basename attribute.
I'm running IntellijIdea version 2016.2, and my application works fine on:
embedded Tomcat v 7.0.73 , using bmuschko gradle-tomcat plugin https://github.com/bmuschko/gradle-tomcat-plugin
remote Tomcat v 7.0.73 deployment with Tomcat Server Idea configuration
To check your resources are really loading (if your properties are not loaded to the page that means you're obviously missing the file), use the following code, as mentioned in https://stackoverflow.com/a/4137991/2759640
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
URL propsURL = ctxLoader.getResource("opto-mapping.properties");
URLConnection propsConn = propsURL.openConnection();
In case you have your resources loaded, openConnecton will throw an exception, that connection to the messages.properties has been already opened (at least I've done that way and tried to make my bundle work also for a long time).
The below code throws an error in Netbeans saying the include statement is not closed. I've tried a few things like #%> and I'm not able to figure out what's up. what am I doing wrong here?
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=request.getAttribute("title")%></title>
</head>
<body>
<%#include file=request.getAttribute("template")%>
</body>
</html>
Try using <jsp:directive.include/>:
<jsp:directive.include file="<%= request.getAttribute("template") %>"/>
Depending on the contents of your template, <jsp:include/> may also work:
<jsp:include path="<%= request.getAttribute("template") %>"/>
The include directive works at compile time (translation time), the path listed in file should be relative to the web application.
The include directive is processed when the JSP page is translated
into a servlet class. The effect of the directive is to insert the
text contained in another file--either static content or another JSP
page--in the including JSP page
if you want to use something more flexible when used to include files jstl tag < c:import >
Using the jstl we can also include those contents or files
which are not a part of the current web application but lying
somewhere outside the web application
I pre-compile some jsp files through ant task of jspc,but it built failed.
errers:
info.jsp(35,2) The attribute prefix fn does not correspond to any imported tag library
info.jsp line 35 :
<c:if test="${fn:length(requestScope.checkDetailInfoList) gt 1}">
ant task xml:
<jasper validateXml="false" uriroot="${basedir}/WebRoot"
webXmlFragment="${dir.WEB-INF}/generated_web.xml"
outputDir="${dir.WEB-INF}/src" />
How should I correct?
You need to make sure the jsp file imports the fn namespace of the JSTL. You'll need a line that looks something like this in your jsp file:
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Also, you'll need to make sure the JSTL jars (jstl.jar and standard.jar) are in your classpath when jasper tries to compile.
Asaph's comments are spot on.
There's one other bit to check: The <fn> tag set was a later addition to the JSTL libraries. Maybe you have an older version of jstl.jar and standard.jar that needs to be updated.