cannot get my JSP to forward to database-handler servlet (innetbeans)

T

terry433iid

I have a JSP that processes some html form (processForm.JSP) and then
forwards to a Java Servlelt that carries out some mysql transactions
to do error checking (under 'project->Source Packages' I have a new
package called 'foo', servlet is DBHandler.java)

processForm.jsp contains the following lines :-

<% if (formHandler.validate()) {
%>
jsp:forward page="/DBHandler" />


I have updated web.xml with the name and location of the DBHandler
(<servlet-class>foo.DBHandler</servlet-class>)

When I compile/deploy/run in netbeans - my web application falls over,
in firefox I get a very brief error (HTTP 404 - the requested resource
() is not available), I get nothing in the netbeans glassfish console.

I have placed some System.out.println to help me debug the sequence of
events, and I can see that DBHandler.java is never called

Can some one please point out what exactly should the syntax be for
forwarding from JSP->servlet (i.e. the JSP forward syntax), should
there be '/' or not?? does web.xml take care of the mapping from name -
location??

any help appreciated
 
M

MikisM

For starters: 'jsp:forward page="/DBHandler" />' should start with '<'
so you should have written like '<jsp:forward page="/DBHandler"/
' (although I believe you just have'nt copied that symbol from you
code). Apart from that, all your jsp:forward syntax is correct.
From the error it would seem that your servlet is not accessible which
is caused by the wrong <servlet-mapping/> element for your servlet (I
guess). You should check it out. Just to be sure you could post
<servlet/> and <servlet-mapping/> contents from web.xml file of the
servete that is troubling you. I will be able to tell you more about
the problem when you do that.
And yes. web.xml is where you put all your servlet mappings. You can
google about the topic: there are plenty of articles, tutorials and
forums that will help you.
 
A

Arne Vajhøj

I have a JSP that processes some html form (processForm.JSP) and then
forwards to a Java Servlelt that carries out some mysql transactions
to do error checking (under 'project->Source Packages' I have a new
package called 'foo', servlet is DBHandler.java)

processForm.jsp contains the following lines :-

<% if (formHandler.validate()) {
%>
jsp:forward page="/DBHandler" />


I have updated web.xml with the name and location of the DBHandler
(<servlet-class>foo.DBHandler</servlet-class>)

When I compile/deploy/run in netbeans - my web application falls over,
in firefox I get a very brief error (HTTP 404 - the requested resource
() is not available), I get nothing in the netbeans glassfish console.

I have placed some System.out.println to help me debug the sequence of
events, and I can see that DBHandler.java is never called

Can some one please point out what exactly should the syntax be for
forwarding from JSP->servlet (i.e. the JSP forward syntax), should
there be '/' or not?? does web.xml take care of the mapping from name -
location??

Is /DBHandler mapped to the servlet?

On the other hand I strongly recommend that you do it the other way
around:
- form is posted to servlet
- servlet does validation and transaction
- servlet forward to JSP

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top