Add Jar to Runtime Path for JSP - java

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.

Related

JSTL tags are not working in eclipse

I am new to JSTL, I downloaded jstl-1.2.jar from here to my web-content/web-inf/lib folder.
In my JSP file, I have mentioned:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
but everytime when I tries to use any JSTL tag, I got the error:
HTTP Status 500 - java.lang.NoClassDefFoundError:
javax/servlet/jsp/tagext/TagLibraryValidator
I am using eclipse photon, tomcat server-8.0.52.
What should I do? I have searched a lot on the internet about this, but I got the same errors. Please help me.
It seems that you are getting error during runtime!
If you are using maven you must add JSTL dependency
or if you are not using maven or gradle you must add the jar to the class path.
Oh sorry! TagLibraryValidator its your problem!
add jsp-api-2.2.jar to your lib folder.
http://www.java2s.com/Code/Jar/j/Downloadjspapi22jar.htm
At last, I got the solution. I just reinstall my java, eclipse, server and reconfigure jstl-1.2.jar. It start working well. I don't know how but this is only solution for me.
ADD FOLLOWING DEPENDENCIES TO A WEB APPLICATION
To use this distribution with your own web applications, add the following JAR
files to the '/WEB-INF/lib' directory of your application:
taglibs-standard-spec-1.2.5.jar
taglibs-standard-impl-1.2.5.jar
taglibs-standard-jstlel-1.2.5.jar
xalan-2.7.1.jar
serializer-2.7.1.jar
If you do not use JSTL 1.0 tags then the "taglibs-standard-jstlel" JAR may be
omitted. If you do not use the XML library, then the Apache Xalan dependencies
may also be omitted.
Sometimes only taglibs-standard-impl-1.2.5.jar library is enough. But if you want to use like forEach loop you should add two libraries to WEB-INF/lib of your project: Impl: taglibs-standard-impl-1.2.5.jar Spec: taglibs-standard-spec-1.2.5.jar
https://downloads.apache.org/tomcat/taglibs/taglibs-standard-1.2.5/README_bin.txt

JSP include param not parsing?

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.

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

Eclipse - Can't find facelet tag library for uri http://java.sun.com/jsf/html

In my index.xhtml , I have a namespace defined like this xmlns:h="http://java.sun.com/jsf/html". The server at this url indicates that the page cannot be found.
Do you know where the page has moved ?
Eclipse Info
Version: Indigo Release
Build id: 20110615-0604
For solving this problem this is what I did :
1. Close the eclipse project
2. Open the eclipse project
3. Right click on the project
4. Click on Validate
=> The (false) warnings are gone.
The XML taglib namespace URI does not point to a real web resource or something. It just points to the same value as the <namespace> entry of the .taglib.xml file of the XML taglib in question in the runtime classpath, which in case of JSF taglibs (and lot others) just happens to be a HTTP URL. In case of Mojarra, you can find the declaration in the /com/sun/faces/metadata/taglib/html_basic.taglib.xml file of the jsf-impl.jar file.
If you're encountering problems with referencing JSF HTML tags, then the cause lies somewhere else.
Previous answers were useful to me. Here I provide an alternative way for solving this issue. I fixed this problem by adding the jar primefaces-[version].jar to the WEB-INF/lib directory.
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
jsf-api.jar and jsf-impl.jar jar in your lib.
Compare the Uri respective to the jsf version you are using.
. The real JSTL 1.0 taglib uses the URI *http://java.sun.com/jstl/core.*
. The real JSTL 1.1/1.2 taglib uses the URI *http://java.sun.com/jsp/jstl/core*.
. Facelets 1.x uses the URI *http://java.sun.com/jstl/core.*
. Facelets 2.x uses the URI *http://java.sun.com/jsp/jstl/core.*
. Facelets 2.2+ uses the URI *http://xmlns.jcp.org/jsp/jstl/core.*

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