- This topic has 5 replies, 4 voices, and was last updated 16 years, 3 months ago by Riyad Kalla.
-
AuthorPosts
-
woodbombMemberI apologize in advance if this should be posted elsewhere: if so, please advise. I have checked/tried examples, docs, faqs, other forums, and google.
I am a servlet newbie but did manage a while back to get a simple servlet to run correctly under an old version of Resin. Now I need to get it to work in the embedded Tomcat 6.0.13 under MyEclipse 6.5. Here’s the sad tale, but true :-).
I have tried to make my application in MyEclipse 6.5/Tomcat 6.0.13 look like various examples on and of the MyEclipse site, to no avail. It seems that the the HTML form I use to collect data is unable to trigger the servlet class that should process the data. I’ve fiddled in various ways with the form page and the web.xml, to no avail. Any (hospitable :-)) suggestions would be appreciated.
========================================================================
Here is the Package Explorer view
1. JSR-SERVLETS
1.1 src
1.1.1 info.jsr.webapp
1.1.1.1 GetPanelistInfo.java
1.2 JRE System Library [MyEclipse 6.5]
1.3 J2EE 1.4 Libraries
1.4 WebRoot
1.4.1 display
SpecifyPanel.html
1.4.2 META-INF
MANIFEST.MF
1.4.3 WEB-INF
lib
1.4.4 web.xml========================================================================
SpecifyPanel contains the following:
<FORM ACTION=”/servlet/info.jsr.webapp.GetPanelistInfo” METHOD=POST>
========================================================================
web.xml contains the following:
<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”2.4″ xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>
<servlet>
<servlet-name>GetPanelistInfo</servlet-name>
<servlet-class>info.jsr.webapp.GetPanelistInfo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GetPanelistInfo</servlet-name>
<url-pattern>/servlet/GetPanelistInfo</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/display/SpecifyPanel.html</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>======================================================================
When I right-click on GetPanelistInfo.java, I select
Run As -> MyEclipse Server Application
and Tomcat 6.0.13 starts up (indicated in the Console)
If I enter:
http://localhost:8080/JSR-SERVLETS/
the content of SpecifyPanel.html is displayed correctly.
However, when I select a button
http://localhost:8080/servlet/info.jsr.webapp.GetPanelistInfo
appears (as I think it should) in the location area of the MyEclipse Web Browser, followed by the msg:
The webpage cannot be found.
=======================================================================
Obviously I’m missing something and that something is probably pretty obvious (to everyone but me?).
Loyal WaterMemberThe following url should work for you. Check the Servlet mapping in your web.xml file.
http://localhost:8080/JSR-SERVLETS/servlet/GetPanelistInfoI would suggest you refer to a servlet tutorial to get more information.
rwwilsonMemberNipun,
Thank you for your reply. I think I was not clear about the nature of the problem. The index.html file is loaded automatically. When I then submit the data via a submit button, the action form is not invoking the servet.
The web.xml file is structured in a way that agrees with each example I have seen. The MyEclipse tutorial does not provide a servlet, but a JSP.
You may be interested to know that the sample application at the tomcat 6 (a war file with included web.xml) documentation site behaves in the same way wrt servlet as my app. I believe I saw a comment that embedded TC and refular TC do not behave in an identical way. Perhaps you could try the sample.war file and see?
Riyad KallaMemberThe index.html file is loaded automatically. When I then submit the data via a submit button, the action form is not invoking the servet.
Just to be clear, Nipun was referring to the POST URL you should use, your Servlet reference is incorrect. By default Tomcat maps servlets to eitiher the /servlets or /servlet sub-path, and then appends the name of the servlet, in your case, GetPanelistInfo.
If you post to that, you should be OK.
rwwilsonMemberThanks for the reply. Are you saying that, in the original web.xml file I posted,
<servlet-mapping>
<servlet-name>GetPanelistInfo</servlet-name>
<url-pattern>/servlet/GetPanelistInfo</url-pattern>
</servlet-mapping>should be replaced by
<servlet-mapping>
<servlet-name>GetPanelistInfo</servlet-name>
<url-pattern>/servlet/info.jsr.webapp.GetPanelistInfo</url-pattern>
</servlet-mapping>?
Riyad KallaMemberRoy,
I would strongly suggest if you want to work with Java Web Development to start with the basics here:
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.htmlIt’s a very hairy environment to work in (100 frameworks that all do the same thing but in slightly different ways, implied variables left and right, acronyms-galore and fundamentals that everyone assumes you know before you get started).
To address your specific question, no, you don’t want to change your Servlet mapping in your web.xml file, you want to change the URL you are posting your form to in your JSP page. But I really think you need to start with that tutorial I linked first, otherwise you’ll just hit another snag most likely with request-scoped variables and forwarding users to different pages (I still get hung on that sometimes).
-
AuthorPosts