Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [wtp-dev] [Dynamic Web Project] JSP - Servlet - web.xml

Questions about the use of WTP are best posted on the newsgroup. This
mailing list is for discussing development of WTP itself.

http://www.eclipse.org/newsportal/thread.php?group=eclipse.webtools

> Tiebreaker: what is that "default package" that was created?
> What to do with it?

When you don't create any folders to hold your classes (called packages in
Java), your classes are considered to be in a "default package". Another way
of thinking about it is that these classes do not have a package. Note that
the package namespace is relative to the directory you specify as java
source root. In your case, it looks like you designated the servlets
directory as a source root. The default package node that you are seeing in
the Project Explorer doesn't correspond to anything physical on disk. It
just there to help you understand the above situation. If you are happy with
your classes not having a package specified, then you don't need to do
anything.

> Second problem linked to the first one:
> using the Eclipse internal web browser, I type in the URL:
> http://localhost:8080/EtiquettesWebProject/jsp/FormUploadFile.jsp
> and I properly get my form.
> I think it would have been more appropriate to type in the URL:
>
http://localhost:8080/EtiquettesWebProject/WebContent/jsp/FormUploadFile.jsp
> What is the rationale behind it?

The WebContent directory is the root for the web content contained in your
app. The reason that the web content root is not set as the project root is
that you don't want to be picking up various project metadata files, java
source files, etc when resolving URLs. You can control the directory that's
designated as the web content root either at project creation or in project
properties (search for web).

> Can you tell me if something is wrong whith this
> because when I submit the form, the servlet is not 
> executed: the form is re-printed on the screen 
> and re-initialized.

You aren't specifying the servlet as the target of your action in your HTML
form element. The standard HTML behavior in this case is to send your POST
request to URL that originates it, which is what you are seeing.

- Konstantin


-----Original Message-----
From: wtp-dev-bounces@xxxxxxxxxxx [mailto:wtp-dev-bounces@xxxxxxxxxxx] On
Behalf Of lmhelp
Sent: Wednesday, February 11, 2009 2:23 AM
To: wtp-dev@xxxxxxxxxxx
Subject: [wtp-dev] [Dynamic Web Project] JSP - Servlet - web.xml


Hi everyone,

Thank you for reading my post.
Let me explain you what I am trying to do and what my problems are.

I created a new "Dynamic Web Project" using Eclipse.
The "Project Explorer" view shows the following architecture:

(L1 = Level 1, ..., L5 = Level 5)
--------------------------------------------------------------
 1. L1 -- WebProject

 2. L2 -- -- Java Resources
 3. L3 -- -- -- src
 4. L3 -- -- -- servlets
 5. L4 -- -- -- -- (default package)
 6. L5 -- -- -- -- -- ClassUploadFile.java
 7. L3 -- -- -- Libraries
 8. L4 -- -- -- -- Apache Tomcat v6.0 [Apache Tomcat v6.0]
 9. L4 -- -- -- -- EAR Libraries
10. L4 -- -- -- -- JRE System Library [jre6]
11. L4 -- -- -- -- Web App Libraries

12. L2 -- -- JavaScript Support
13. L2 -- -- build
14. L2 -- -- WebContent
15. L3 -- -- -- jsp
16. L4 -- -- -- -- FormUploadFile.jsp
17. L3 -- -- -- META-INF
18. L3 -- -- -- WEB-INF
19. L4 -- -- -- -- lib
20. L4 -- -- -- -- web.xml

21. L1 -- Servers
22. L2 -- -- Tomcat v6.0 Server at localhost-config
--------------------------------------------------------------

As you can see, I have created:
- a folder: "jsp" (line 15.),
- a "Source Folder": "servlets" (line 4.)
- two files: a JSP "FormUploadFile.jsp" (line 16.)
             and a servlet "ClassUploadFile.java" (line 6.).

Roughly,
- the JSP is a HTML form that I want to use
  to choose the file I want to upload,
- the servlet does the uploading job.

My first problem is the following:
I do not really understand the architecture above
and didn't find the reference documentation that
explains it.
I only had a glance at the file:
".settings\org.eclipse.wst.common.component"
which seems to be linked to the problem...
----------------------------------------------------------------------------
----
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="WebProject">
        <wb-resource deploy-path="/" source-path="/WebContent"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
        <wb-resource deploy-path="/WEB-INF/classes"
source-path="/servlets"/>
        <property name="context-root" value="WebProject"/>
        <property name="java-output-path"/>
    </wb-module>
</project-modules>
----------------------------------------------------------------------------
----

Tiebreaker: what is that "default package" that was created?
What to do with it?

Second problem linked to the first one:
using the Eclipse internal web browser, I type in the URL:
http://localhost:8080/EtiquettesWebProject/jsp/FormUploadFile.jsp
and I properly get my form.
I think it would have been more appropriate to type in the URL:
http://localhost:8080/EtiquettesWebProject/WebContent/jsp/FormUploadFile.jsp
What is the rationale behind it?

Third problem:
I have to customize the "web.xml file".
Here is what is presently looks like:

----------------------------------------------------------------------------
----
<?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";
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
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">

  <display-name>WebProject</display-name>

  <servlet>
    <display-name>ClassUploadFile</display-name>
    <servlet-name>ClassUploadFile</servlet-name>
    <servlet-class>ClassUploadFile</servlet-class>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>ClassUploadFile</servlet-name>
    <url-pattern>/FormUploadFile</url-pattern>
  </servlet-mapping>
</web-app>
----------------------------------------------------------------------------
----

Can you tell me if something is wrong whith this
because when I submit the form, the servlet is not 
executed: the form is re-printed on the screen 
and re-initialized.

Here is the "FORM" in the JSP file:
----------------------------------------------------------------------------
----
<FORM ENCTYPE="multipart/form-data" ACTION="" METHOD="POST">
  <TABLE STYLE="background-color: lightgreen;" CELLPADDING="5">
    <TR>
      <TD> Choose a file to upload: 
      </TD>
    </TR>
    <TR>
      <TD><INPUT NAME="uploadedfile" TYPE="file" style="width: 227px"/></TD>
    </TR>
    <TR>
      <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Submit" /></TD>
    </TR>
  </TABLE>
</FORM>
----------------------------------------------------------------------------
----

Thanks in advance for your help,
--
Lmhelp
-- 
View this message in context:
http://www.nabble.com/-Dynamic-Web-Project--JSP---Servlet---web.xml-tp219518
89p21951889.html
Sent from the Eclipse WTP - general mailing list archive at Nabble.com.

_______________________________________________
wtp-dev mailing list
wtp-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/wtp-dev



Back to the top