I want to display a jsp content in a panel

Hello,

I need a help on how to display a jsp content in a panel or any itmill layout.

I have some functionality that I want to use a jsp and display within my application which is itmill based, now I dont have an idea of how should I do that, leave alone if it is possible.

I count on your help on this.

thanks.

Hi,

You can use the Embedded component for showing HTML/JSP-pages.

Embedded jsp = new Embedded();
jsp.setType(Embedded.TYPE_BROWSER);

Hi again

I trried to use the above solution as follows

Embedded jsp = new Embedded();
		jsp.setType(Embedded.TYPE_BROWSER);
		jsp.setWidth("100%");
		jsp.setHeight("100%");
		jsp.setSource(new ExternalResource("ITMILL/themes/example/jsp/news.jsp"));

and I get this

HTTP Status 404 - /ITMILL/themes/example/jsp/news.jsp

type Status report

message /ITMILL/themes/example/jsp/news.jsp

description The requested resource (/ITMILL/themes/example/jsp/news.jsp) is not available.

Should an external resource be completely outside the application??

If you use some resource from inside your theme folder, you can easily use a ThemeResource.

So in you case, instead of the ExternalResource, use the following

jsp.setSource(new ThemeResource("jsp/news.jsp")); I suppose ExternalResource wants to have an absolute path, or the relative path you are providing is incorrect.

sorry wasnt logged in,

I tried to use the Themeresource but instead i get the jsp content as code.


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<body>
<h1 class="h1-blue">Hot news!</h1>
</body>
</html>

am I missing something?

Theme resource will not work for this situation as this resource will just read contents of a file, referenced from a theme folder. But JSP needs to be interpreted/compiled by the web container, so only external resource can be used for this.

If you need a complete URL you can easily construct one using information from http servlet request object or window’s url (getURL() method)

Upd. Looking at your status code it seems that the web container is trying a wrong URL - /ITMILL/themes/example/jsp/news.jsp - note the first “/” character. You can try to append your application name like “myapp/ITMILL/themes/example/jsp/news.jsp”

Still no luck, I tried all the given methods and tried even some other hacks, but I just get the jsp content, not the compiled one.

Pls If someone have an example of this I would appreciate, for some reason, I need to have some jsp content in some of my panels.

I will appreciate for the solution to this.

thanks :oops:

Can you access your JSP page directly from the browser and get the expected result?

If i access the jsp directly from the browser

http://localhost:8081/SocialNetwork2/ITMILL/themes/example/jsp/news.jsp

I get


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>

<body>
<h1 class="h1-blue">Hot news!</h1>
</body>
</html>

Thanks

Hi, you can make a JSP servlet mapping in WEB.xml file and have your JSP page in webcontent root of your project.


   <servlet>
        <servlet-name>myJSP</servlet-name>
        <jsp-file>/somepage.jsp</jsp-file>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>myJSP</servlet-name>
        <url-pattern>/extJSP</url-pattern>
    </servlet-mapping>

I don’t know if this helps.

I tried that too, but not getting the results.

Has anyone done this before?

Weird. I agree with the solutions presented by dll. I cannot see why the Embedded component does not display the compiled jsp, if the accessing the it directly with browser does… Anyone?

For a sanity check I would put the jsp outside the ITMILL folder. I don’t that should make any difference, but …

Hi, I played a bit with the test jsp and here is what I discovered:

  1. Locating jsp inside the toolkit’s theme folder will not work because when you request a file like “/myapp/ITMILL/themes/mytheme/jsp/test.jsp”, the request is handled by the toolkit application servlet. This servlets decides how to fetch the requested resource - from itmill.jar file or from a web content, but in any case, the application servlet , not the web container will read the actual test.jsp file and feed to output stream - you’ll get your plain JSP file, with all code inside.

  2. You can open JSP files in embedded component - in order for JSP to work, a web container must process your request. To allow this - you’ll have to change toolkit application servlet mapping from “/" to something like "/myapp/”, so your application start url will be a bit different: http://localhost:8080/myapp/myapp , where first “myapp” is your context and second “myapp” is your application servlet mapping. Now you can place JSP files in the web application root folder and reference them from your application using an Embedded component:


Embedded jsp = new Embedded();
 		jsp.setType(Embedded.TYPE_BROWSER);
 		jsp.setWidth("200px");
 		jsp.setHeight("200px");
 		jsp.setSource(new ExternalResource ("out.jsp"));

But when you change your toolkit application mapping from “/" to "/myapp/” , do not forget to add another mapping for your application servlet - “/ITMILL/*” :


&lt;servlet&gt;
		&lt;servlet-name&gt;ToolkitPlusDemo&lt;/servlet-name&gt;
		&lt;servlet-class&gt;com.itmill.toolkit.terminal.gwt.server.ApplicationServlet&lt;/servlet-class&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;application&lt;/param-name&gt;
			&lt;param-value&gt;com.alee.tplus.demo.ToolkitPlusDemoApplication&lt;/param-value&gt;
		&lt;/init-param&gt;
	&lt;/servlet&gt;

    &lt;servlet-mapping&gt;
		&lt;servlet-name&gt;ToolkitPlusDemo&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/demo/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

    &lt;servlet-mapping&gt;
		&lt;servlet-name&gt;ToolkitPlusDemo&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/ITMILL/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

This way JSP will work and display correctly.

Hope this helps,
Dmitri

Thank you so so much,

This one works! :lol:

Great!

Finally, many thanks to dll for the help! Greatly appreciated :slight_smile:

At your service :slight_smile:

Hi,
I have a save kind of issue (I want to display a jsp content)
so i added the /UnixwatchdogWeb/* on url -pattern in web.xml file.

here is the content from web.xml

UnixwatchdogWeb /UnixwatchdogWeb/*

now if i run the appication (from eclipse) its point to the URL http://localhost:8080/UNIX_WATCHDOG_NEW/
and display the content as

Directory Listing For /


Filename Size Last Modified
Data.xml 0.2 kb Thu, 24 Nov 2011 04:16:20 GMT
DiplayGraph.jsp 0.9 kb Thu, 24 Nov 2011 04:15:42 GMT
FusionCharts/ Thu, 24 Nov 2011 04:18:52 GMT
GenerateReport.jsp 0.6 kb Thu, 24 Nov 2011 04:15:55 GMT
VAADIN/ Thu, 24 Nov 2011 05:26:28 GMT


Apache Tomcat/7.0.16

if i change the the address in the browser as http://localhost:8080/UNIX_WATCHDOG_NEW/UnixwatchdogWeb
it display the screen from my application(login screen). but the formats and Themes is totaly gone :(.

Can you help me out. ??
:bored::bored: