掲示板

Custom Servlet in web.xml

thumbnail
13年前 に Gaurav Vaish によって更新されました。

Custom Servlet in web.xml

New Member 投稿: 12 参加年月日: 10/11/14 最新の投稿
Hi,

I want to write a custom servlet in Liferay. I have done the following:

Created, compiled the code and create a jar, say, custom-servlet.jar
Added the jar in WEB-INF/lib folder
Registered the class in WEB-INF/web.xml file


It's a very simple servlet - "doGet(...) { out.println("Hello, World!"); }" types.

When I browse to the URL, I get the error "404 Page Not Found".
On the console, I see the error "[PortalImpl:3812] Current URL /liferayportalapp/uss generates exception: null".

Please help.
thumbnail
13年前 に Gaurav Vaish によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 12 参加年月日: 10/11/14 最新の投稿
Gaurav Vaish:

When I browse to the URL, I get the error "404 Page Not Found".
On the console, I see the error "[PortalImpl:3812] Current URL /liferayportalapp/uss generates exception: null".


Investing in some more detail... the actual exception seems to be "NoSuchLayoutException".
thumbnail
13年前 に Amos Fong によって更新されました。

RE: Custom Servlet in web.xml

Liferay Legend 投稿: 2047 参加年月日: 08/10/07 最新の投稿
Hi Gaurav,

Can you post your web.xml changes? Is this the portal web.xml or a custom portlet?
thumbnail
13年前 に Gaurav Vaish によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 12 参加年月日: 10/11/14 最新の投稿
It's the portal web.xml


<servlet>
	<servlet-name>hwServlet</servlet-name>
	<servlet-class>com.xyz.HelloLRServlet</servlet-class>
	<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
	<servlet-name>hwServlet</servlet-name>
	<url-pattern>/abcd/servlets/hw</url-pattern>
</servlet-mapping>


In tomcat, it's the {tomcat-root}/webapps/ROOT/WEB-INF/web.xml configuration file.
thumbnail
13年前 に Mati Khan によって更新されました。

RE: Custom Servlet in web.xml

Junior Member 投稿: 25 参加年月日: 10/11/01 最新の投稿
Hi,

If you are using a portlet plugin, its easy to add in web.xml file servlet entry and it will work.

Can you explain why you need it in a jar file?
thumbnail
13年前 に song jh によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 2 参加年月日: 11/01/25 最新の投稿
I have the same question!
thumbnail
13年前 に David H Nebinger によって更新されました。

RE: Custom Servlet in web.xml

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Gaurav Vaish:
It's the portal web.xml


<servlet>
	<servlet-name>hwServlet</servlet-name>
	<servlet-class>com.xyz.HelloLRServlet</servlet-class>
	<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
	<servlet-name>hwServlet</servlet-name>
	<url-pattern>/abcd/servlets/hw</url-pattern>
</servlet-mapping>


In tomcat, it's the {tomcat-root}/webapps/ROOT/WEB-INF/web.xml configuration file.


By adding the servlet into liferay, you have to remember that the servlet filters will be invoked, which is probably the source of your exception...

The bigger question is why it needs to be part of liferay... For example, if you've got portlet code you also want exposed as a servlet, then you build a separate portlet project (war) and add the necessary servlet info in there; that way you control the servlet filter(s), mappings, etc.
thumbnail
13年前 に Gaurav Vaish によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 12 参加年月日: 10/11/14 最新の投稿
Hi David,

David H Nebinger:

The bigger question is why it needs to be part of liferay... For example, if you've got portlet code you also want exposed as a servlet, then you build a separate portlet project (war) and add the necessary servlet info in there; that way you control the servlet filter(s), mappings, etc.


Thanks for the pointers...

I have been able to crack the puzzle.

Created a custom portlet.
I totally missed out the point that the portlets are also available at "/portlet-id" context path. Created a servlet there and am using that.

Thanks.

--
Gaurav
http://www.incoleg.com
thumbnail
13年前 に Stephan Huber によって更新されました。

RE: Custom Servlet in web.xml

Junior Member 投稿: 28 参加年月日: 09/03/27 最新の投稿
Hi Gaurav,

did edit the web.xml within the deployed liferay directly on the application server?
We have similiar problems with liferay 6 and GlassFish.
Changes in the web.xml directly on the server are ignored by GlassFish even after restarting!

Workaround:

1. Undeploy liferay-portal-6.0.5.war
2. Copy the new web.xml into WEB-INF/ in liferay-portal-6.0.5.war
3. Redeploy liferay-portal-6.0.5.war

This worked for us!

Regards,
Stephan
thumbnail
10年前 に Erick Christian Rosales Cruz によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 5 参加年月日: 13/11/28 最新の投稿
Hi, I used the Liferay Portal bundled with Tomcat. how can I undeploy the liferay_portal.war?

Thanks. I've missing a lot ot time trying to fix this but I haven't been able to achieve this.
thumbnail
10年前 に Erick Christian Rosales Cruz によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 5 参加年月日: 13/11/28 最新の投稿
Stephan Huber:
Hi Gaurav,

did edit the web.xml within the deployed liferay directly on the application server?
We have similiar problems with liferay 6 and GlassFish.
Changes in the web.xml directly on the server are ignored by GlassFish even after restarting!

Workaround:

1. Undeploy liferay-portal-6.0.5.war
2. Copy the new web.xml into WEB-INF/ in liferay-portal-6.0.5.war
3. Redeploy liferay-portal-6.0.5.war

This worked for us!

Regards,
Stephan


Hi Stephan... IS there any other way to modify the web.xml...

I'm triyng to integrate the Crystal Reports Viewer but I'ev got is:
POST http://localhost:8080/CrystalReportViewerHandler 404 (No Encontrado) --- Not Found
Here is the web.xml from

liferay-portlet \ docroot \ WEB-INF \ web.xml

and this is the content:


<!--?xml version="1.0" encoding="UTF-8"?-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
	<servlet-mapping>
		<servlet-name>CrystalReportViewerServlet</servlet-name>
		<url-pattern>/CrystalReportViewerHandler</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>CrystalReportViewerServlet</servlet-name>
		<servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
	</servlet>
	<context-param>
		<param-name>crystal_image_uri</param-name>
		<param-value>/crystalreportviewers</param-value>
	</context-param>

	<context-param>
		<param-name>crystal_servlet_uri</param-name>
		<param-value>/CrystalReportViewerHandler</param-value>
	</context-param>
	<context-param>
		<param-name>crystal_image_use_relative</param-name>
		<param-value>webapp</param-value>
	</context-param>
	
	<context-param>
    <param-name>crystal_exception_info</param-name>
    <param-value>long</param-value>
    </context-param>  	
</web-app>


What am I doing wrong!!!!

As some other people has been experienced... The Crystal Report (MyReport.rpt File) is rendering only the first page, but when you try to navigate to the next page or try to print you got that error.... POST http://localhost:8080/CrystalReportViewerHandler 404 (No Encontrado) --- Not Found

Could anyone help me!?
9年前 に Javier Vera によって更新されました。

RE: Custom Servlet in web.xml

New Member 投稿: 18 参加年月日: 14/08/01 最新の投稿
hey man did you manage to achieve this servlet thing?
peace
thumbnail
8年前 に John Voltaire Maximo によって更新されました。

RE: Custom Servlet in web.xml

Regular Member 投稿: 106 参加年月日: 15/06/19 最新の投稿
can I do this on my custom-portlet's web.xml??