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

[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

Related

Image is not showing in JSP File

I am having problems displaying an image in my .jsp file.
The image no_image.jpg is located inside the following directory of my Spring MVC application:
SpringProject\src\main\webapp\assets\images\no_image.jpg
I am trying to access it through my .jsp file like this:
<img src="${pageContext.request.contextPath}/assets/images/no_image.jpg"></a>
Project structure (using apache Netbeans IDE 11):
However this does not seem to display the image, does anyone have any ideas why?
Probably the Expression Language is treated as plain text. To tell the JSP engine to process such expressions, add <%# page isELIgnored="false"%> before the <html> tag in your JSP page (at the top, where you have other "%#"-like directives or JSTL imports). Unfortunately, this parameter's value defaults to true.
I have found the solution. For anyone else experiencing this issue, a possible solution is to put the following into your spring configuration .xml file: (Where you define your base package for the project, my one is named spring-config.xml)
<mvc:resources mapping="/assets/**" location="/assets/"/>

JSP link to Another JSP file in a different Folder

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.

Can you change the text content of a JSP file by code (on the fly)

Lets say I have a jsp page in my webapp. The code inside it displays some info.
Can I change the code (text) inside this jsp using a Rest Controller. I want to dynamically replace its code by opening the file and changing its content.
I want to change file content via http request:
"/api/change-jsp?newcontent=sometext&file=example.jsp"
--> The corresponding rest controller now does his job.
Will that work or not ?
Ps: 'newcontent=sometext' contains jsp code (EL)
It won't work — jsps are compiled at runtime by the servlet container when the app starts. The JSP compiler will not expect the jsp to change.
But why change it in the first place? Just make the jsp ask for the information it needs.

JSP page included in servlet not rendering satisfactorily

I have two jsp files (header.jspf and footer.jspf) that I want to include in a page produced by the doGet method of a servlet (Menu.java). I'm doing this by use of the RequestDispatcher.include() method. The header.jspf file only contains html so it renders fine. The footer.jspf file, however, contains both EL and JSP tags, neither of which render on the servlet page produced by Menu.java.
Looking at the source code of the page produced by Menu.java I understand that the reason for this problem is that the EL and JSP is not evaluated prior to being included in the servlet so it is just presumed by the browser that it is html.
While I'm guessing that what I'm trying to do may be poor (and deprecated) practice, I'd just like to find out if there is a way to get an included jsp file to render in a servlet just as it would in a jsp page when it contains EL and jsp tags?
I'm thinking that this question is general enough not to require my code to be posted, however if I'm wrong please tell me so and I will update with my code.
Not sure if there is a way to have RequestDispatcher.include() files processed, but including the footer explicitly will very likely work:
<%#include file="footer.jspf" %>

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.

Categories

Resources