aspose file tools*
The moose likes JSP and the fly likes xml mapping Head First Servlets and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "xml mapping Head First Servlets and JSP" Watch "xml mapping Head First Servlets and JSP" New topic
Author

xml mapping Head First Servlets and JSP

Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Hello,

This is in reference to the code snippet from Head First Servlets and JSP page 359.

The heading says Going straight from the request to the JSP without going through a servlet

I was eager to try out the code but wondered how the web.xml would look if I have say a JSP called Test.jsp under root of my application, is the code below the right one:

web.xml


What should come in place of ...??

Thank you.


Regards,
Samaresh Gupte
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

the code given here is incomplete. <jsp:config> is used to declare the nature of some or all jsp pages like - Scripting invalid, el-ignored etc.
the complete code will be


avi sinha


SCJP 5.0 SCWCD 5.0
Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Thank you Avi.

But I'm really confused because it is unclear how the mapping from an HTML to the particular JSP ( which is a servlet eventually) done

Like in Servlet mapping it is very evident from the web.xml viz. through <servlet-name> , <url-pattern> and <servlet-class>

But the same transperency is not with the JSPs. So my point is how the HTML finds/maps the servlet that is generated from the JSP?
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Samaresh Gupte wrote:Thank you Avi.

But I'm really confused because it is unclear how the mapping from an HTML to the particular JSP ( which is a servlet eventually) done

Like in Servlet mapping it is very evident from the web.xml viz. through <servlet-name> , <url-pattern> and <servlet-class>

But the same transperency is not with the JSPs. So my point is how the HTML finds/maps the servlet that is generated from the JSP?


truly saying , i didn't understand you question. making some points clear to you

1> Html never finds or maps a servlet or a jsp . its the container who finds it.
2> container finds the correct servlet or jsp based on matching url-patterns. and for url pattern it doesn't matter whether it is a jsp file or just a servlet.
for jsp file it is:


i don't see any difference here . a html form just gives the information about the url pattern (action) nothing else and url pattern is related to servlet name not to the type of servlet,package etc

avi sinha
Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
I apologize if I was unable to putforth my point clearly.



1. <web-app>
2. <servlet>
3. <servlet-name>MyServlet</servlet-name>
4. <jsp-file>/Results.jsp</jsp-file>
5. </servlet>
6. <servlet-mapping>
7. <servlet-name>MyServlet</servlet-name>
8. <url-pattern>/go</url-pattern>
9. <servlet-mapping>


In the above case what if there is no servlet existing?
say there is only Results.jsp and I want to redirect to this jsp after hitting submit button on my HTML.

I will say action="Result.jsp" on my HTML, right?

But then what goes in web.xml?
or is it that instead of <servlet-class> I put in <jsp-file>?

or is it that I'm confusing between <jsp-file> and <jsp-config>?
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

i can understand now .
the point is for jsp there is no need of mapping to be done in web.xml
it can work without mapping but its not like, we can't do it.
it depends upon the need of the application. you can still write the action="go" or "/go" and it will work.

avi sinha
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Samaresh Gupte wrote:
or is it that instead of <servlet-class> I put in <jsp-file>?

ya of course you are just replacing <servlet-class> tag with <jsp-file> nothing else. you can treat a jsp file just like a servlet.

or is it that I'm confusing between <jsp-file> and <jsp-config>?

<jsp-file> and <jsp-config> are for different purposes .<jsp-config> declares additional features which you want in your jsp-files. it has nothing to do with requests and response here.

avi sinha
Samaresh Gupte
Greenhorn

Joined: Oct 03, 2009
Posts: 20
Thanks a lot Avi Sinha..now the point is absolutely clear
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 453

Samaresh Gupte wrote:Thanks a lot Avi Sinha..now the point is absolutely clear


you're welcome.

avi sinha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml mapping Head First Servlets and JSP