Farakh khan

Ranch Hand
+ Follow
since Mar 22, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Farakh khan

Hello,

I have two totally different modules e.g. user and employees.
When I login to employees the user module and if I login to user module by logging out the employees then employee module throwing the following error:


These two modules or on the same domain e.g.


Why when one module logins then other throwing NPE?
How can I run two different sessions on same domain?

Best Regards


3 years ago
Paul I never said to not use JSP or never talked against JSP. If you can fix my problem in JSP show me. I am anxiously waiting
3 years ago
I just WASTED my time here in this forum. Despite fixing my problem discussing issues about something else.
3 years ago
In this forum I seen everybody is talking a lot about here and there but not coming to the point.

Can you fix my problem?
3 years ago

Tim Holloway wrote:"optimization" is not the problem. Or rather, Java Strings are not the optimal way to express HTML. Which is why we also have JSPs.



Thanks for your advice. I appreciate and will try to follow it. Please help me to fix my present problem
3 years ago

Tim Holloway wrote:

Jesse Silverman wrote:
I feel my lip curling. No, this is really ugly code that could be made a lot more maintainable. It looks like something a beginner would write before learning better, in fact.
Yes, it's nicer to have everything in one file, but sometimes "nicer" isn't better.



I confess its very ugly code. I tried as under to optimize it:



Here is the problem which I am trying to fix it:

3 years ago
How can I mark this answer as correct one?
3 years ago

Jesse Silverman wrote:Do you understand the following code pasted from my jshell?
Wouldn't something similar help you in your problem?

jshell> String s1 = "Huey";
s1 ==> "Huey"

jshell> String s2 = "Dewey";
s2 ==> "Dewey"

jshell> String s3 = "Louie";
s3 ==> "Louie"

jshell> String[] pages = {s1, s2, s3};
pages ==> String[3] { "Huey", "Dewey", "Louie" }

jshell> System.out.println( pages[1] );
Dewey





Yes you are right

This is working as I was intended

Thanks from the bottom of my heart
3 years ago

Jesse Silverman wrote:Let's back up even further.

Do you want that this code prints out exactly one of the Strings, or all of them in succession?

If you want to print out only one, there is no need at all for a for loop, as Paul stated.

If you mean to print out the first one, then the second one, then the third one, you can either place them into an array and print the 1st, 2nd, 3rd (and maybe the 40th) inside a simple for loop with indexing, or you could continue your approach (which scales poorly to more strings) by fixing the if statements and placing the print() calls inside the { } code for each if else statement.



Thanks for your favorable replies


This is working fine but let me understand if I say:

I am thinking that in first loop if statement pageNo should be 1 and currentPage should be 2 and should not be run but unfortunately its printing and ignoring other statemetns. Why? I want to understand the logic as to why its not going to the next else if statement where pagrNo is 2 and its equal to currentPage
3 years ago

Jesse Silverman wrote:

Farakh khan wrote:

Campbell Ritchie wrote:But you always know there will be a first page unless your text is length 0. What do your selection statements in lines 31‑38 do?


With due respect I am already not able to fix my posted question. So not able to answer more questions. If you know anything that could be helpful then please post it. I don't know you are answering my question or adding more questions to me ):



OK.  I agree with the others, but let's see if I can get you to see it.

Because currentPage does NOT change inside your for loop, the code you have that says:



does the same thing in each test.  If the first one matches, the others never get executed.
If the first one doesn't match, neither will the next two.

The smallest change you could make would be to explicitly specify the page numbers in your if statements, instead of saying currentPage, so they are actually different.

While you could make that work if you put the right stuff in the { } braces after the tests, I agree that it would be more normal, and neater, to just create an array of Strings and to then refer to the members of that array by index.  What if later you have eight or nine or ten different possible pages?  The logic as you have it would be fine if there were ever just one or two, but scales poorly when the number of possible pages goes higher.

However, the if tests that you have coded don't even work to pick from one of two or three pages, because the test you are doing in each one, f(pageNo == currentPage) is exactly the same in each.






Obviously the following will work:

I am looking for as to how can I control it dynamically?




3 years ago

Junilu Lacar wrote:

Farakh khan wrote:Hello,

Here is my code:


I hear a phone ringing... I bet it's the late 1990s calling to say "You need to stop doing that!"




Share your 2021 call if you are able to fix my problem
3 years ago

Tim Holloway wrote:We spend a lot of time discouraging people from trying to write complex application logic on JSPs using scriptlets.


This is not jsp. I am using servlet to handle all tasks that a JSP can do because JSP is being translated into Servlets and I don't think its complex. Its very simple code and even a beginner can understands very well.

Tim Holloway wrote:
Here, however. you've transgressed in the opposite direction.

Your life will become much easier if you use the popular servlet+JSP architecture where a servlet handles the business logic, collects the results in JavaBeans, then forwards to a JSP that uses the JavaBeans to populate the display and - in conjunctions with JSTL tags, to determine what blocks of HTML to show or hide based on the bean values.



Is this related to my question? None of the reply I got here is relevant to my question or nobody tried to fix my problem rather than talking about here and there
3 years ago

Campbell Ritchie wrote:But you always know there will be a first page unless your text is length 0. What do your selection statements in lines 31‑38 do?


With due respect I am already not able to fix my posted question. So not able to answer more questions. If you know anything that could be helpful then please post it. I don't know you are answering my question or adding more questions to me ):
3 years ago
Hello,

Here is my code:


Here is output:



Perhaps image links here not working. So I am copy pasting
https://pasteboard.co/K59yqqG.png
https://pasteboard.co/K59yP9j.png
https://pasteboard.co/K59z4Bu.png

This code has two problems:
1) First and second page is working fine but when goes to 3rd page its changing the current page number to 3 instead of moving cursor to the next 3rd page link
2) if 5 pages (numbers) to be displayed for paging like then when next clicked. It changes last displayed page as

I spent approximately 2 days but not able to fix it

Best Regards
3 years ago