I'm new to liferay and java so this is probably very simple.
I've successfully created portlet complete with a configuration.jsp file. In my portlet view.jsp I can successfully reference images:
<img src="${renderRequest.contextPath}/images/image1.png" />
But in my configuration.jsp the contextPath is empty.
QUESTION: What needs to be done in order to get the same path I get in my view.jsp?
I've created this pastebin showing my full code and this pastebin to show a simpler case.
Use the below code.
<img src="<%=request.getContextPath()%>/images/image1.png"/>
Ensure that you have configured the portlet name properly in portlet.xml and web.xml
Related
So I am currently trying to test a project whose facets I have changed, namely, I added a dynamic web component to it. In order to do so I decided to do a basic html form, and associated servlet with it.
However, when I try to run it I get a 404. Interestingly enough, a project I had which worked fine today is now also facing a similar issue. Though my practice servlet, which is used a template for everything else, does not have this issue.
the form follows this format:
<form action="myServlet">
<input type = "submit"/>
</form>
the servlet simply returns a writer.println("Hello World");
Error message:
HTTP Status 404 - /userName/LoginServlet
type Status report
message /userName/LoginServlet
description The requested resource is not available.
Apache Tomcat/8.0.38
Edit, and now the one servlet that worked also stopped working throwing the same error. If it helps, I am trying to run it from eclipse, by right clicking on my html page and then selecting for it to run on my server.
Problem was rather simple to hidden, since the name was refactored, the servlet mapping in eclipse did not show this. Deleting and recreating the servlet fixed it.
At least for now.
I have a problem with uploading a large file (>max_upload_size). Why all form fields are null (when uploading this file) in form validate method?
I tried to manage this by asking if file is null and return action error if so, and while debugging seems ok, i get no response to my browser. I have already managed this on another project. This former project worked on Bea web server, while this current is on Jboss.
Can you post the what your jsp looks like.
Also do not forget to include this (enctype="multipart/form-data") in your jsp form definition:
<html:form action="/uploadme" enctype="multipart/form-data">
<html:file property="myfileToupload"/>
</html:form>
I have a project that I can see the JSP's... However Jboss shows me the servlets so in the address bar all i can see is:
"appservleer?=AppDev"
This is an example not the actual address...but with that info only how can I know which JSP is being displayed at that moment by JBoss.
or am I understanding this Jboss, servlet, JSP incorrectly?
Some guidance would be appreciated.
Thanks.
You cannot know which jsp is being displayed unless the developer decided to give hints about it.
A jsp is just a view technology that the servlet uses to render a response. That is, typically, the jsp will be parsed and html will be generated. However, the developer of the servlet may decide to write to the response himself. So nothing can really tell you if what you got came from a jsp or from another source, even if you had a url like www.mydomain.com/page.jsp. Nothing guarantees the response you are seeing in your browser was generated from a jsp.
The only way to know for sure which JSP is used for rendering is to look at the source code of the servlet that is mapped under (in your example) "appservleer".
Look in web.xml which servlet is mapped with this path, and open the source code of this servlet. Then figure out the execution path, starting with the doGet(...) or the doPost(...) method, and see to which JSP it is forwarded in the end...
Good luck.
You should always start with the web.xml file which will eventually lead you to the actual jsp file that is displayed. Start with the servlet mapping and check which servlet is invoked for the url. Then dig into the servlet to find out which jsp it is redirected to. If you are using any application framework then look for the implementation to findout the mapping. For e.g. in spring the spring configuration files or the controller classes tells you where the calls are redirected to.
I have created 3 portlets (testimonial portlet, directory portlet, polling portlet), and I want to call testimonial portlet from directory portlet. How to do this? Kindly help me.
I have written the following code in my view.jsp file of directory portlet:
<%# taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:renderURL var="linkURL" portletName="testi" windowState="maximized" />
<br>
Testimonial
I can redirect in another page, but I got error like
This portlet has been undeployed. Please redeploy it or remove it from
the page.
Should I make changes in liferay-portlet.xml? Kindly help me.
portletName attribute value , you specified seems incorrect.
Thats the reason, you are getting that message.
I just checked giving incorrect name "test" as portletName whereas there isnt any portlet with name test.
If <portlet-name>test</portlet-name> is the entry in your liferay-portlet.xml ,
then give portletName as test_WAR_testportlet, it will work.
If other portlet is Liferay's Out of Box portlet, you can utilize PortletKeys class.
HTH
I had same requirement. But i am very new in Liferay...
So i have not much more knowledge of Liferay API.
So I used web service for fetch portlet data to another portlet. Its really interesting and very easy..
You can find more help from this.
Jersey RestFul webService
I done this and all working very well.
Thankssssss
In my web application one of my pages is uploading a photo to the path
/usr/local/rac/picture-name-goes-here
The photo is uploading fine, but I need to access it in another page and when I try to access it from my JSP, it will not show up, I am guessing my path to the photo is incorrect
The code in my JSP to access the photo looks like the following.
<tr>
<td>
<img src="/usr/local/agent/photo-name-here.jpg"/>
</td>
</tr>
Am I incorrect with this path to the photo?
If it helps, I am running my web application from Tomcat which is in the directory
C:\Tomcat6
I will eventually be moving this over to a linux machine and expect to share the same path to the photo.
There is one major misconception here. HTML is executed by the webbrowser, not by the webserver. The webbrowser downloads HTML, scans for any resources which needs to be downloaded as well (CSS, scripts, images, etc) and fires a new HTTP request for each of them. All resources should point to a valid URL, not to some local disk file system path which the client machine has no notion of.
There are basically two ways to solve this "problem":
Add a new Context to Tomcat's /conf/server.xml:
<Context docBase="/usr/local/agent" path="/images" />
This way they'll be accessible through http://example.com/images/... and you'll be able to use the following <img>
<img src="/images/photo-name-here.jpg"/>
Create a Servlet which basically gets an InputStream of the image and writes it to the OutputStream of the response along a correct set of headers. You can find here a basic example of such a servlet and here a more advanced example. When the Servlet is mapped on /images/* in web.xml, the images are accessible by http://example.com/contextname/images/... and you'll be able to use it as follows (assuming that the JSP/HTML file is located in the context root):
<img src="images/photo-name-here.jpg"/>
src="/usr/local/agent/photo-name-here.jpg" <- this URL is a local address in your server, to show up your images you have to set a valid HTTP address like:
http://www.yourdomain.com/images/photo-name-here.jpg
To accomplish that you will need to upload the foto to a localpath that is inside in your www root folder.
If your webapp is installed in
/home/apache/www/website/
you will upload your images to a folder like:
/home/apache/www/website/images/
and then your HTTP address will be
http://www.yourdomain.com/images/photo-name-here.jpg
I got a little confuse with your two paths in /usr/ and C:\Tomcat
I encourage you to put the upload localpath folder parametrized, so you will be only modifying the config file instead of every function or method that access to that local path.