Write a path to call a particular servlet. - forms

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

Related

tomcat eclipse java ee default package

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.

404 error in gwt project- servlet is correctly defined in web.xml but still getting 404 error

I am working to create a web app using GWT+Java backend. The host page is "App.html"
The app also has a RPC, and the host page when initially loaded, makes an RPC call.
However this is the message I am getting from Javascript console in Google Chrome browser-
POST http://app.sparkcrawler.com/com.arvindikchari.auth.App/AuthenticationService 404(Not Found)
Given below are the contents of my web.xml--
<?xml version................................>
<servlet>
<servlet-name>AuthenticationService</servlet-name>
<servlet-class>com.arvindikchari.auth.server.AuthenticationServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuthenticationService</servlet-name>
<url-pattern>/com.arvindikchari.auth.App/AuthenticationService</url-pattern>
</servlet-mapping>
What am I doing wrong here? How do I resolve this error?
The problem is with your servlet mapping.
Basically, you have two things in web.xml (regarding servlets):
the <servlet> tag, which defines the alias for the servlet, and its
fully-qualified name (In your case AuthenticationService and com.arvindikchari.auth.server.AuthenticationServiceImpl)
the <servlet-mapping> which specifies a url-pattern for a given alias
(taken from the <servlet> definitions).
It should be like
<servlet-mapping>
<servlet-name>AuthenticationService</servlet-name>
<url-pattern>/authenticationService</url-pattern>
</servlet-mapping>
I think your servlet mapping url pattern looks wrong.
normally when mapping any servlet <url-pattern> would be like this.
<`<url-pattern>/{app name}/{servlet name}</url-pattern>`
here app name would be same as registered app name which is in gwt.xml file.

Adding an html form to an existing servlet

I have an existing servlet that has a form and takes in data and executes correctly. We've been given a new requirement to add a page that will allow the user to modify some of the values in the servlet properties file via a web form.
I've developed the package to do this. I'm looking for a way to add the page and package to the existing servlet. I would rather not create a separate servlet on Tomcat for this.
I know how to create new html pages in the existing servlet, but I'm unsure how to execute this class file without making it a standalone servlet.
Any help is appreciated.
I solved my problem. It seems I just needed to add the additional servlet to my web.xml. Resolved.
<servlet>
<description></description>
<display-name>Servlet1</display-name>
<servlet-name>Servlet1</servlet-name>
<servlet-class>com.mycompany.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ExporterServlet</servlet-name>
<url-pattern>/ExporterServlet</url-pattern>
</servlet-mapping>
<servlet>
<description></description>
<display-name>Servlet2</display-name>
<servlet-name>Servlet2</servlet-name>
<servlet-class>com.mycompany.Servlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/Servlet2</url-pattern>
</servlet-mapping>

how to deploy GWT app to tomcat

I searched this site for answer to this question and couldn't find a solution.
what i did is that i simply compress the war directory in my eclipse GWT app project then rename it to .war then drop it to tomcat webapps folder.
when i run the web app, the first screen is successfully shown but when i call a servlet within my src code it gives me resource not found by tomcat server.
i'm sure i have added entry for servlet in web.xml file and the app worked well when i run it in eclipse gwt dev mode. something prevent my servlets (standard servlets not GWT RPC servlets) to be found and executed by tomcat. what could be the reason?
UPDATE
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>OAuth</servlet-name>
<servlet-class>org.goauth.server.OAuthServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OAuth</servlet-name>
<url-pattern>/goauth/oauth</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>OAuthCallback</servlet-name>
<servlet-class>org.goauth.server.OAuthCallbackServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OAuthCallback</servlet-name>
<url-pattern>/goauth/callback</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>service</servlet-name>
<servlet-class>org.goauth.server.OAuthServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/goauth/service</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>OAuthConfirm</servlet-name>
<servlet-class>org.goauth.server.OAuthConfirmServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OAuthConfirm</servlet-name>
<url-pattern>/goauth/confirm</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>GOAuth.html</welcome-file>
</welcome-file-list>
</web-app>
Error
nothing in tomcate logs files
the only error in browser is :
HTTP Status 404 - /goauth/oauth
type Status report
message /goauth/oauth
description The requested resource (/goauth/oauth) is not available.
Apache Tomcat/6.0.20
I found the problem :
for invoking my servlet i was calling a url of the format : "/goauth/OAuth"
this worked with eclipse gwt plugin in dev mode but not when i deploy war to tomcat server.
the solution is that my url pointing to my servlet should be of the form :
String href = GWT.getHostPageBaseURL()+"goauth/OAuth";
so we need to tell tomcat the full url by prefixing servlet url with GWT.getHostPageBaseURL().
Take a look at how to create a GWT .war in eclipse: http://blog.elitecoderz.net/gwt-and-tomcat-create-war-using-eclipse-to-deploy-war-on-tomcat/2009/12/
In your mapping, try changing
/goauth/oauth
to /OAuth

gwt - problem accessing servlet in inherited module

I'm trying to divide my app into modules and I'm stuck with this problem:
I have a widget MapServiceWidget in one module called "webvisualisation" that uses the RPC to get the data from MapService Rpc interface. I'm inheriting this module in another GWT module called "led" (I packed "webvis..." into jar with sources, added in module "led" deffinition). Then I try to create this widget in the second ("led") module and get message
"Problem accessing /led/mapservice reason NOT FOUND".
And sure it can't find it cause mapservice is defined in inherited "webvisualisation" module.
The question is why it's looking for this servler implementation in "led" module not in "webvisualisation" where it's defined? I checked all module definitions and web.xml files several times and consulted documentations, it seems ok.. but it's not. If my description is not clear I can post some config/source files.
This is web.xml for webvisualisation module
<!-- Servlets -->
<servlet>
<servlet-name>mapservice</servlet-name>
<servlet-class>pl.gmike.webvis.server.MapServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mapservice</servlet-name>
<url-pattern>/webvisualisation/mapservice</url-pattern>
</servlet-mapping>
And for led it's just ordinary generated sample file
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>pl.led.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/led/greet</url-pattern>
</servlet-mapping>
Seems that you're bumping into a classpath problem. Maybe check that your webvisualisation.jar is in the WEB-INF/lib directory of your web application.
I got it working. I just added servlet and servlet mapping entries to "led" modules web.xml so it look like this now:
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>pl.led.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>mapservice</servlet-name>
<servlet-class>pl.gmike.webvis.server.MapServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/led/greet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mapservice</servlet-name>
<url-pattern>/led/mapservice</url-pattern>
</servlet-mapping>
As You can see the mapservice servlet is mapped here to /led/mapservice URL where GWT seems to look for it, unlike in original "webvisualisation" module web.xml where it was mapped to /wevisualisation/mapservice .
I'm not very satisfied with this solution, it works but it requires adding a servlet mapping in WebApps web.xml for every servlet in inherited module that I want to use or that is used somewhere in this inherited module.
Still I would like to know why servlet definitions and mappings from inherited modules are not included in WebApps web.xml during compilation/linking... I think it should work without such hacks, so there's something I'm doing wrong.