JSP include param not parsing? - java

I am using JSP includes in a project and have recently set up my environment on another computer. But now when I serve the project on Tomcat I get the following error:
HTTP Status 500 - java.io.FileNotFoundException: The requested resource (/rootprojectlevel/secure/${param.includeIt}) is not available
The code that I have in my jsp looks like this:
<jsp:include page="sideBar.jspf" >
<jsp:param name="includeIt" value="correspondingmenu.jspf" />
</jsp:include>
In sideBar.jspf I have the following which gets the parameter passed from that first JSP include:
<jsp:include page="${param.includeIt}" />
Maybe the JSP expression language isnt getting evaluated?
This issue only happened after creating my new environment in Eclipse, so maybe something with Tomcat is not configure correctly for JSP's? Or maybe my project path is not included? I've been racking my brain but can't seem to find the answer.

Related

Eclipse JSTL completion: how to make visible new JSTL variables defined by my custom tag

We've built a custom taglib which declares (via Tag TEI class) a new variable which becomes visible both at script level and JSTLS level.
Eclipse completes correctly the object whitin scriptlets but does not recognize it within JSTL. Are we missing some config in Eclipse? Might it be something within the TLD of the taglib?
here's an example:
<w:helper name="myBean" class="com.customer.Example"/>
<%
myBean.method(); //here the completion works, both invoking ctrl+space on "myB" and "myBean."
%>
${myBean.field} // here no completion at all
I would like Eclipse to be able to complete on both the lines.
Any help?
Added info:
the TLD declares jspversion 1.1
DTD declaration for DTD is http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd
Edit 2016-10-21:
We're using Eclipse Mars.
We've tested TLD version 2.0 with DTD 2 without success.
We've also tracked the problem to Eclipse being unable to complete any JSP-EL variable. The following example does not provide completion.
<c:set var="test">hello</c:set>
${te // here ctrl+space will NOT proposte "test"
<c:set var="second" value="${te}"/> // here too not working

JSP cannot find default bundle for i18n

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).

How to fix Faces Servlet (javax.faces.webapp.FacesServlet) not found in web context - cannot configure PrettyFaces DynaView?

I currently added the prettyfaces-jsf2-3.3.3.jar to my netbeans project. I also added the pretty-config.xml in the WEB-INF folder with the following test rewrite rule:
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<url-mapping id="viewRecipe">
<pattern value="/#{ RecipeBean.filterRecipeName }/" />
<view-id value="/faces/viewRecipe.jsf" />
</url-mapping>
With this configuration the url
http://localhost:8080/wie-koche-ich/Spaetzle
//wie-koche-ich is the name of the netbeans project
should refer to the viewRecipe.jsf page and set the filterName to Spaetzle. But when I enter the url the glassfish 4.0 server returns a 404 page and the log says "Faces Servlet (javax.faces.webapp.FacesServlet) not found in web context - cannot configure PrettyFaces DynaView".
What exactly throws this Exception and how can i fix this?
It seems that the pretty-config.xml wasn't loaded.
This basically means, that PrettyFaces isn't able to find the mapping of the FacesServlet. See:
https://github.com/ocpsoft/prettyfaces/blob/3.3.3/core/src/main/java/com/ocpsoft/pretty/faces/config/servlet/WebXmlParser.java#L73
Did you manually define the mapping for the FacesServlet in your web.xml? If not, you could try to add it. Or you could perhaps try to debug this class to find out what's going on. Actually this class should (in case of a Servlet 3.x) environment, iterate over all the servlet registrations and find the servlet.

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.

Add Jar to Runtime Path for JSP

I'm using IBM's Rational Software Architect (essentially Eclipse I suppose). I have a JAR file that contains Proxy classes to access a Web Service (JAX-RPC). I've created a Dynamic Web Project with a simple JSP page in which I'm trying to consume the Web Service using a Proxy class from this library. Code from the JSP page:
<jsp:useBean id="queryProxy" scope="session" class="location.DataSearchProxy" />
<% queryProxy.setEndpoint("http://localhost:9080/CIDataService/services/DataSearch"); %>
<%=queryProxy.query("SELECT street, city, prov, postcode FROM v_location WHERE c1 = '48704'") %>
At this point I have added the External JAR file to the Libraries section of the Build Path, however when running the JSP page on WebSphere in-browser; I get the "DataSearchProxy cannot be resolved to a type" error.
I have also tried using:
<%# page import="location.DataSearchProxy" %>
<% DataSearchProxy queryProxy = new DataSearchProxy(); %>
<% queryProxy.setEndpoint("http://localhost:9080/CIDataService/services/DataSearch"); %>
<%=queryProxy.query("SELECT street, city, prov, postcode FROM v_location WHERE c1 = '48704'") %>
But I get the same error. I have a feeling for this type of Web-Project I may need to reference it in some other way so it can be resolved from JSP pages or other Beans in the project. I may be going about this in the wrong way and I hope someone can point me in the right direction for consuming a Web Service from JSP.
You probably want to package the jar into your application.
Remove it from your build path (we'll add it back later)
Put the JAR in the root of the EAR, drag it to your Application project, not the WEB App
Open your Web project properties and go to Java EE dependencies. You should see the jar offered there. Select it and it will add it to both the build time classpath and also the Manifest so that it's picked up at runtime.

Categories