Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp that posts to itself

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been writing using MVC since day one. With only rare exceptions, I get/post to servlets and use jsps only for viewing. Now I find myself knee deep in an application understood by nobody in the company and written by a programmer who is no longer here. It's all JSP pages, not a page controller or dao anywhere in sight.

I'm really having trouble understanding this concept of a page that posts back to itself. How is this even processed when there is no doGet() or doPost() in the compiled servlet code, just a service() method? It's difficult to debug, especially since the page also contains several custom tag libraries, all undocumented, of course.

Between the self-posting and the tangled mess of custom tags, I just can't follow the logic in this beast. Can someone explain at a high level how this self-posting/self-getting concept works? If I can't grok this thing soon I'm going to strip it down to the sheet metal and re-write it the correct way, but that will take months.

Google didn't help me in this case, just some people asking how to do it, in posts from 10 years ago.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:Now I find myself knee deep in an application understood by nobody in the company and written by a programmer who is no longer here. It's all JSP pages, not a page controller or dao anywhere in sight.

Eeesh! I feel your pain.

Google didn't help me in this case, just some people asking how to do it, in posts from 10 years ago.

Yeah, it's been about 14 years since I've seen code like that. (Other than here, of course.)

In essence the first display of the JSP is a GET which is intended to display the initial state of the page. The post back to the page is intended to perform whatever action the page is intended to submit, and then re-display the page with any updates. This was usually done by detected the HTTP method; GET versus POST.

Beyond that, it was really the Wild West, and just about anything went.

Things really get messy fast doing things that way, which is why it went out of favor long long ago.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Bear. It's code like this that makes me wish I'd had the sense to go to dental school and become an orthodontist.

Here's the sort of crap I'm dealing with. btw, ptwasl.jsp is the name of the containing page. Not my naming convention; you don't want to go down that road.


When the page initially loads, the psmsdatepicker fields contain todays date and the posting-period-select does not have any entries with the "selected" attribute. So if I choose new start and end dates and one of the choices from the select box, then submit, when the page reloads (haven't these people heard of Ajax?!?) I should see the new start and end dates because ${start} and ${end} are now request attributes, and the option I picked from the select box should now have the "selected" flag set, again because of a request attribute.

Am I correct so far?

If I'm understanding that correctly then I guess I need to dig deeper into the custom tag classes to see how that "value" attribute is being managed by the tag files. I think the fog is starting to clear a little bit. This sort of Rubber Duck Debugging helps.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's odd that the form is a GET method -- they're not even following the conventions of the bad conventions.

I should see the new start and end dates because ${start} and ${end} are now request attributes

Not automatically. The form submission will create request parameters of those names -- I guess; it's hard to know what the custom tags are doing behind the scenes.

Yeah, you've inherited a cluster. My condolences.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:It's odd that the form is a GET method -- they're not even following the conventions of the bad conventions.

Welcome to my world. At least these pages don't contain scriptlets. We have enough of those going around already. Someone made a valiant attempt to do things correctly by using JSTL and EL. They failed miserably, but at least they went down swinging.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I should see the new start and end dates because ${start} and ${end} are now request attributes, and the option I picked from the select box should now have the "selected" flag set, again because of a request attribute.

You've lost me here.
How do ${start} and ${end} become request attributes?
Is that some magic that goes on in the custom tag?

Something somewhere must be doing a request.getParameter --> request.setAttribute("start", someVal)" for that to happen right?!?!?


 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:
You've lost me here.
How do ${start} and ${end} become request attributes?
Is that some magic that goes on in the custom tag?

Imagine how I feel. You have a lot more experience than me. I've spent hours single-stepping my way through this code and still can't make sense of it. Here's the doTag method, but all I see is it returning a String of HTML. I still can't figure out where those ${start} and ${end} attributes are used.



At this point I really think my best option is to re-write that page using a servlet controller and and DAO to fetch the data. I've done enough hair-pulling over this one already.
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!