I'm trying to set up a dynamic web app using Eclipse Juno and Tomcat 7. My problem is that i can only get my servlet to run if my file structure is
MyProject/Java Rescources/src/(default package)/MyServlet.java
I've read i should avoid using the default package (don't know why) but when i try to use a different package:
MyProject/Java Resources/src/myPackage/MyServlet.java
I get the error message:
HTTP Status 404 - /MyProject/MyServlet
The requested resource is not available
Its only a small test project so i can start a new workspace and create the project anew if necessary. I suppose i have to change a path somewhere but i don't know where or how.
I got it working using the following in web.xml
<servlet>
<servlet-name>QNumInput</servlet-name>
<servlet-class>myPackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>QNumInput</servlet-name>
<url-pattern>/QNumInput/QNumReq.do</url-pattern>
</servlet-mapping>
The index.html file calls this with the tag:
<form name="getQNumForm"
action="http://localhost:8080/MyProject/QNumInput/QNumReq.do"
METHOD = "POST">
<B>Enter Question Number 1 to 200</B>
<INPUT TYPE="TEXT" NAME="qNumber">
<INPUT TYPE="SUBMIT" VALUE="Request Question Text">
</form>
It did not work at first so i cleaned the tomcat work directory by right clicking on the server (not sure if this is necessary) It still did not work so i gave up and exited Eclipse. This must have saved the new settings because when i fired up Eclipse again and tried it again it worked ok.
Thanks for the help.
DG
You will need to make sure your <servlet-mapping> and <servlet> elements in web.xml are correctly set.
Related
Context:
LiferayFaces + Eclipse IDE.
liferay-plugins-sdk-6.2-ce-ga6,
liferay-faces-bridge-api-3.2.4-ga5-sources.jar
Hi all:
As a begginer in the JSF programming world within Liferay Platform, I've started to create a JSF Portlet Project following the 'Creating a JSF Portlet'
learning path.
I've successfully created the JSF Portlet Project and deployed it on the Tomcat Server, and it's even working as expected.
The problem is that eclipse is displaying some errors in the facelet 'view.xhtml', despite of the fact that the portlet is working fine. The content of such file is:
<?xml version="1.0"?>
<f:view
xmlns="http://www.w3.org/1999/xhtml"
xmlns:aui="http://liferay.com/faces/aui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head />
<h:body>
<h:outputText value="#{i18n['guestbook-jsf-hello-world']}" />
</h:body>
</f:view>
And the errors I can see are:
should insert missing 'title' element (in the '' line) (in fact, it's not an error but a warning).
f:view is not recognized (in fact, is's a warning).
h:head is not recognized.
h:body is not recognized.
Self-closing syntax (/>) used on a non-void HTML element.
It seems that the JSF tags are not recognised, although the portlet is working fine.
Can anyone explain to me what's going on with eclipse IDE and how I can prevent eclipse IDE from showing those errors messages? Thanks in advance.
Additional info (#BalusC):
I think JSF Project has a facelet for the view mode, as the content of portlet.xml includes:
<portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>/views/view.xhtml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
Moreover, within Project -> JavaResources -> Libraries -> Ivy you can find, among others, the following libraries:
jsf-api-2.1.21-sources.jar
jsf-impl-2.1.21-sources.jar
liferay-faces-util-3.2.4-ga5-sources.jar
liferay-faces-bridge-api-3.2.4-ga5-sources.jar
liferay-faces-bridge-impl-3.2.4-ga5-sources.jar
liferay-faces-portal-3.2.4-ga5-sources.jar
So the JSF implementation library do exists.
Moreover, within Project -> Properties -> Java Build Path -> Order and Export, all the entries are selected, so the JSF/LiferayFaces related libraries are included into the JSF Project.
Any idea/suggestion is welcome.
Thanks.
I cannot reproduce these issues anymore in Liferay Developer Studio (or Liferay IDE) 3.3.1+.
I have the following setup:
Project A - A Dynamic Web project, which depends on project B.
Project B - A Dynamic Web project, that defines a Test.jsp file.
If I launch project B on the server, or move the Test.jsp to project A and launch project A on the server. it works just fine, and I can access the .../Test page'.
But when the Test.jsp remains in project B and I launch project A, although I do see the project-b.jar in the war file and the classes from project B does load, which means most of the process works ok, and only the jsps are not added...
How can I solve this?
In Case anyone would get to this question, the solution described in here works well, though was not very clear at first:
In my project B, place your jsp files so:
src/main/webapp/META-INF/resources/${path-to-jsp}/file.jsp
In src/main/webapp/META-INF/ create a web-fragment.xml with your variation of the following content:
<web-fragment
metadata-complete="true"
version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
<servlet>
<servlet-name>jspTest</servlet-name>
<jsp-file>/${path-to-jsp}/file.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>jspTest</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-fragment>
and now if your buildpath is defined correctly, then clean-build both project B, and project A and run the server again... it works!
Using gwt logs jar I am able to display logs on my console. But now I wanted to add logs in my olgs file from cient side, as we do using log4j on server side. So i reffered to http://code.google.com/p/gwt-log/wiki/GettingStarted this link but i dont see any client side logs getting generated in my log file.
Following is my gwt.xml file
<inherits name="com.allen_sauer.gwt.log.gwt-log-DEBUG" />
<set-property name="log_DivLogger" value="DISABLED" />
<!-- In gwt-log-3.0.3 or later -->
<inherits name="com.allen_sauer.gwt.log.gwt-log-RemoteLogger" />
<set-configuration-property name="log_pattern" value="%d [%t] %p - %m
%n" />
Following is my web.xml file
<servlet>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<servlet-class>com.allen_sauer.gwt.log.server.RemoteLoggerServiceImpl</servlet-class>
<!--
The `symbolMaps` parameter specifies the server directory
containing the GWT compiler symbol maps output, which is used
for stack trace deobfuscation
-->
<init-param>
<!-- This value assumes a GWT compile with '-deploy war/WEB-INF/deploy/' -->
<param-name>symbolMaps</param-name>
<!--
Modify the param-value based on your server environment. Some web servers
use your `war` directory as the 'current working dir', while other
vendors will do something different. You may use trial and error. Specify the
relative path you think should work, then check the server log after forwarding
the first client log message to the server. If the directory cannot be found,
gwt-log will report the full path which it tried.
-->
<param-value>WEB-INF/deploy/detectfiles/symbolMaps/</param-value>
</init-param>
<!--
Additional or alternate directories may be specified via additional parameter
which also begin with `symbolMaps`. This may be useful if you deploy to multiple
server environments which use different directory structures or have a different
notion of what the 'current working directory' is.
-->
<init-param>
<param-name>symbolMaps_2</param-name>
<param-value>WEB-INF/deploy/detectfiles/symbolMaps/</param-value>
</init-param>
<!-- Optionally enable CORS (http://www.w3.org/TR/cors/)
<init-param>
<param-name>Access-Control-Allow-Origin</param-name>
<param-value>http://your-applications-origin</param-value>
</init-param>
-->
</servlet>
<servlet-mapping>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<url-pattern>/com.renault.detectfiles/gwt-log</url-pattern>
</servlet-mapping>
I have added log on clinet side as follows
Log.debug("Hi this is a debug log");
First of all, make sure that you compile your GWT application with the additional parameter -deploy war/WEB-INF/deploy/.
Second, make sure that symbol maps exist in the directory
WEB-INF/deploy/detectfiles/symbolMaps/. I observed that symbolMaps go to the directory WEB-INF/deploy/<module-name>/symbolMaps/ when I compiled. Here, detectfiles does not look like your module name. Because, in the url-pattern, you have specified com.renault.detectfiles as the module name.
These might be the possible cause of not seeing the log.
I need a help with getting right path so that my request from a JSP page to a servlet works fine. Right now its giving me an error Servlet not found .. I am working in eclipse. My directory is like this ::
At the top level is my Project_Name 2_8_2012. Now inside JavaResources i have a Src folder inside which i have a package Mypackage inside which i have a TimeServlet.java and TimeManagement.java.
my JSP page is in WebContent/jsp/Page.jsp
Now from Page.jsp i send a request on input submit button click. Basically a form is submitted
<form id="timeform" name="timeformname" action="/2_8_2012/jsp/timeservlet" method="post">
which goes to my web.xml where i have this code ::
<servlet>
<servlet-name>Timeserv</servlet-name>
<servlet-class>
MyPackage.TimeServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Timeserv</servlet-name>
<url-pattern>/2_8_2012/jsp/timeservlet</url-pattern>
</servlet-mapping>
but i get the error servlet not found.
To open a page.jsp on my browser i go to link
http://localhost:8080/2_8_2012/jsp/Page.jsp.
and it opens fine.
How should i give a path so that my servlet is called up ? Thanks..
change the URL-PAttern to
/jsp/timeservlet and check
I have a common GWT application that is using (trying to) Rocket-Framework to implement a CometServerServlet.
After I have registered my servlet in web.xml and my app.gwt.xml, like this:
App.gwt.xml:
<servlet path="/server" class="myapp.server.MyCometServlet"/>
web.xml
<servlet>
<servlet-name>myCometServlet</servlet-name>
<servlet-class>myapp.server.MyCometServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myCometServlet</servlet-name>
<url-pattern>/myapp/server</url-pattern>
</servlet-mapping>
Jetty apparently doesn't find the CometServerServlet from which my MyCometServlet extends:
WARNING: Error starting handlers
java.lang.NoClassDefFoundError:
rocket/remoting/server/comet/CometServerServlet
Caused by:
java.lang.ClassNotFoundException:
rocket.remoting.server.comet.CometServerServlet
That is strange, because I've added the Rocket jar to my project.
Could someone explain why this error happened?
I could understand if I "registered" the servlet in a wrong way or something, but at what point Jetty (or who?) looks for the CometServerServlet and fails at finding it?
Adding the jar to your project (e.g. in some IDE) will remove compilation errors, because the jar can be found at compile time.
But Jetty needs the library at runtime, and the usual way to provide it, is by putting it in the WEB-INF/lib folder of your project.
Of course, make sure to redeploy the app afterwards (e.g. if you're using Dev Mode, click refresh in the "Development Mode" view).