JSP link to Another JSP file in a different Folder - java

I am new to net beans and JSP. I created index.jsp in Web Pages folder and i want to link a text in index.jps to another JSP called CompanyLogin.jsp in Web Pages/MainLogins/ComapanyLogins/CompanyLogin.jsp.
I tried <li>Company</li>
but it didn't work. Plese tell me hoe to solve this problem. Thank you for any help

The slash at the URL's beginning makes it absolute to your host. But usually the first part of the path is the context name. It's safest to use a relative path like
Company
Here relative means relative to the location of index.jsp.

Related

How to define more than one jsp file in web.xml?

[enter image description here][1] since I'm a newbie to jsp, I'm having lots of doubt buzzing around me.
I need to know how to define more than one jsp file in web.xml.
thanks in advance :).
We do not declare any JSP files in web.xml, we only mention the initial page to load. by default it could be index.jsp or default.jsp. once the default page is loaded the navigation to another jsp will be handled either bu servlet redeirect method or using href with page name to redirect.
Contact us

Access files inside workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\

I have a spring web project which basically Test webApp and capture screenshot of pages. The path of the saved image looks something like below:
"\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
\Demo\WEB-INF\Results\Test\1118015800\error\error_ST001_1.jpg"
I am trying to display the saved image on a JSP page and so far success has been elusive. I tried different combination of relative path also I tried to give absolute path but it doesn't work. My image tag looks something like this
<img src="<c:url value="/WEB-INF/Results/Test/1118015800/error/error_ST001_1.jpg" />" />
Does anyone have any idea on displaying the image? Could it be because files are stored inside the .metadata folder of Eclipse workspace that I am not able to display any image?
This is because the WEB-INF directory is special. The web container won't serve files from that location - that behavior is defined in the Servlet Spec.
You can either create a servlet that takes requests from the client, loads images (e.g. using getResourceAsStream()) and streams them back, or move the images to a different place in your web app hierarchy.

Call jsp page from autocompete function in liferay

$(function() {
$("#ac1").autocomplete('getdata.jsp');
}
I'm calling that page in liferay6..
so, What sort of changes I will have to make in portlet.xml and another file ..
I'm getting this error....
http://localhost:8080/web/guest/getdata.jsp?q=abc 404 Not Found
(This error is coming in Firebug not in UI)
Thanks in Advance,
Mayur Patel
First of all, if you are using a portlet specific resource as the data, you should probably be using portlet:resourceURL or liferay-portlet:resourceURL instead of a static address to the file getdata.jsp. ResourceURLs create fully qualified URLs that target your own portlet. The resource served are supposed to be content fragments instead of full blown pages. That way they are especially suitable for AJAX-calls.
Where is the getdata.jsp file located? You could define the full path to the file i.e. /my-service/getdata.jsp instead of relying on the relative address that points to the /web/guest url-mapping. That way you can be sure that the file is found provided that you are not going to share the portlet with others that might not install the portlet the same way as you have done.

accessing the .java file from .jsp file in Eclipse

in eclipse IDE how can i access a java class from .jsp
exactly like accessing a servlet from a jsp file ?
in other word, what should i replace with question marks "????????"
<form name="myForm" action="???????????????" method="post">
</form>
when i run engine.java file from "mypackage" package tomcat application servers shows this address in the address bar.
http://localhost:8080/rouyesh/servlet/mypackage.engine
anybody can help please?
You'll need to use whatever the path relative to your current URL is, or the absolute path, just as you would with files. It might be prudent at this point to investigate a web framework, however, before you destroy your product with insanity :P.
If you just need to call the class from your JSP page, then just do it.
If you need to expose your class through an URL, the standard way to do so, is to enter through a servlet (exposed in the usual way) and call the class inside the servlet.
Your particular framework may provide such functionality out of the box. Read the documentation carefully.

JSP: FileReader with relative path throws FileNotFoundException

I have some embedded Java code in which I'm trying to load a properties file that is located in the same folder as the JSP file:
Properties titles = new Properties();
titles.load(new FileReader("titles.txt"));
The code above throws a FileNotFoundException.
How exactly does one refer to the 'current folder' in this situation?
Two things:
JSPs should not contain java code. use an mvc framework (spring mvc, stripes etc) as controller and use the JSP as view only. That makes life a lot easier
You are not supposed to access resource files through the file system in a web app, use classloader access as suggested by redlab. The problem is that a web app may or may not be unpacked on the file system, that's up to the servlet container
The main problem I see is that you can't make any valid assumptions as to what the path is, as you don't know where your compiled JSPs are
So: create a controller class, put the properties file in the same folder and load it from the controller class via getClass().getClassLoader().getResourceAsStream("titles.txt");
FileReader requires absolute path, or relative the where the java is run. But for web applications this is usually done via /etc/init.d/tomcat startup and you can't rely on what is the current dir.
You can obtain the absolute path of your application by calling servletContext.getRealPath("/relative/path/to/file.txt")
You can get the relative part of the URL by calling request.getRequestURL().
That said, you'd better use this code in a servlet, not a JSP - JSP is a view technology and logic should not be placed in it.
By using the classloader that loads your class you can get the file easily.
getClass().getClassLoader().getResourceAsStream("titles.txt");
However I don't know if it will work with JSP
You could also use ServletContext.getResourceAsStream(""), but then you have to give the full webcontent-relative path.

Categories

Resources