• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

From index.jso the Servloet in not called

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have this code in the index.jsp:




In my web.xml I put:


The Servlet is like this:



When I debug after pressing the button in the form, it doesnt goes to the Servlet.

Any idea, please?

Regards, Isaac
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Try fixing your action path to match the action path on the server e.g.

<form method="GET" action="/action">

or

<form method="GET" action="/application_path/action">

or

<form method="GET" action=".../action">

etc.

With:
<form method="GET" action="action"> the path is relative to the location of your jsp and the jsp would need to be in the root of your webapp I think...

This is isn't like struts or spring or what not, you are writing raw html in your jsp hence the path needs to match the path on the server.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I am in the index in the URI I can see this:


http://localhost:3308/leanRouteWeb/#



and the form is like this:

<form method="GET" action="/leanRouteWeb/action">



The button looks like this:

<a href="#" class="action-button shadow animate blue">Test Performance</a>



even with this changes I cant reach the Servlet when debuging

Any idea, please?

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should I also change it here?
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try replacing:
System.out.println("numberLinesPau");

with

Printwriter pw = new PrintWriter(response.getOutputStream());
pw.println("numberLinesPau");
pw.close();

this is not like a CGI script, you need to write to the servlet output stream.

 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isaac Ferguson wrote:Should I also change it here?



NO
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the JspFaq for information on very simply including the contact path in the action URL. You should be doing this for all resources such as action, script files, style sheets, images, and so on.

It's not complicated at all, you simple fetch the application path with an EL expression.
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A.J. Côté wrote:or <form method="GET" action=".../action">



This is bad advice. Using page-relative paths in a Java web app is going to cause problems. If not now, then later.

or

<form method="GET" action="/application_path/action">



It's a called the context path, not the "application path".
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

A.J. Côté wrote:or <form method="GET" action=".../action">



This is bad advice. Using page-relative paths in a Java web app is going to cause problems. If not now, then later.

or

<form method="GET" action="/application_path/action">



It's a called the context path, not the "application path".



Of course, it is much easier to tell a user that he doesn't know what he is doing and that he needs to learn a bunch of advanced concepts instead of helping him at the level he currently is. We all started somewhere...
 
Sheriff
Posts: 26779
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A.J. Côté wrote:Of course, it is much easier to tell a user that he doesn't know what he is doing and that he needs to learn a bunch of advanced concepts instead of helping him at the level he currently is. We all started somewhere...



I don't agree. It's true that all beginners tend to make the same mistakes, but handing them a bandaid and hoping they will learn correct terminology and concepts later isn't the way to go, I don't think. That just guarantees more substandard code will be produced and in many cases "later" will never happen if they have something sloppy which works most of the time. And especially in this case we aren't talking about a bunch of advanced concepts, just a couple of basic principles.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

A.J. Côté wrote:Of course, it is much easier to tell a user that he doesn't know what he is doing and that he needs to learn a bunch of advanced concepts instead of helping him at the level he currently is. We all started somewhere...



I don't agree. It's true that all beginners tend to make the same mistakes, but handing them a bandaid and hoping they will learn correct terminology and concepts later isn't the way to go, I don't think. That just guarantees more substandard code will be produced and in many cases "later" will never happen if they have something sloppy which works most of the time. And especially in this case we aren't talking about a bunch of advanced concepts, just a couple of basic principles.



You have a point. I guess the right balance is optimal. Rest assure, I am pretty tight with the devs in my team. But for somebody who is trying to submit a plain html form to a servlet, it might be interesting to help him succeed. As a bonus, he will understand better the inner-working of the servlet/jsp/struts or whatever he uses later since he started from scratch.

I have seen developpers with 2 or 3 years experience that know nothing about httpRequest.getParameter, httpResponse.getOutputStream, CGI script were you just read from environment variables and write to standard output. Heck, they haven't got a clue how the browser communicates with their fancy application. This might lead to trouble too...

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying with an even more simple example I already worked woth Servlet in the past and this one is just not working I think it is not the itself but the system environent?

The code is:

index.jsp



ConvServlet.java


web.xml




When I press the button in the form it produces a 404 error:



Any idea of why it just doesnt find the resource?

 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not listening. In the following:you should not be hard-coding the context path.

Use the EL expression to get the context path. That way, it can never be wrong.

See the JspFaq for details: https://coderanch.com/how-to/java/ResourceUrlProblems

Doing anything else is not advised.

If it still doesn't work once we're sure that the path is correct, then we know to start diagnosing elsewhere.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote it like this:



and the web.xml


I checked and the content of: ${pageContext.request.contextPath}/ is /conversionMoneda which is the name of the web app.

Then the action is been built like this:



I got 404 error same than before. I use NetBeans running in a mini Mac

 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your web.xml indicates that ConvServlet is in a package called "web" but there is no package statement in your code. Maybe you just left that off for brevity, but make sure the package statement is there and that the class file is in /WEB-INF/classes/web.

 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And btw, your context path looks correct now. Congrats on figuring out the EL code.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a package called web, then inside it the is the class ConvServlet. The web.xml indicates that the class is inside the web package. Isnt it?




 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, "package web;" is what I was looking for. So you're good there.

Do you know how to use the debugger in the web browser to look at the request and response?

Let's start simple. Add this to your processRequest() method:



Try it again. Does that line display in the console?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing in the console, when I debug the request in the browser I get

http://localhost:3308/conversionMoneda/ for the redirectURLCC

thats the only relevant data I got. When I submit the data, it just doesnt in into the Servlet so I cant debug.

Any more idea, please?

 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget the jsp for the moment. What do you get if you enter this in the browser:

localhost:8080/conversionMoneda/ConvServlet

I'm going to enter this code and see what I can see.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I type this:



I get this:




and If I type this:



I get the same. (Tomcat is config to use the 3308 port)

Any idea, please?


 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isaac Ferguson wrote:
Convertir esta cantidad: <input type=”text” name=”valor” value=”${param.valor}”/>
<input type="submit" value="Submit">


Did you copy and paste this code from somewhere?

Look carefully at the quotation marks in those lines. See the difference? The second is valid code, the first is not. That's why you are seeing "%E2%80%9D" in your URL.

Fix your quotation marks and you'll be okay.
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to see the difference in the posting. I didn't see it until I copied your code into Netbeans and even then it took a few minutes before I spotted it. The strange URL in the debugger had me puzzled for a bit, then I looked up that encoding. It turns out "%E2%80%9D" is the code for a quotation mark.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the configuration of Tomcat to 8080 and it works now

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic