Bala Krishna

Ranch Hand
+ Follow
since Jan 26, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bala Krishna

Hi,
I've recently started looking into Struts2 and am learning it by building a simple CRUD web application. Compared to Struts1.x, I like the improvements in Struts 2.x, where I can have the same Action class for all operations for my entity. What I mean is, Struts 1.x forced me to have one Action class for each of the CRUD operations of my entity - since execute() method was the only method in the action class, that'd be, well, executed. With Struts2, I can create just one Action class, and implement different methods, one for each of the CRUD operations. Based on how I map them in my struts.xml, the framework will call the specific method for the action I'm invoking. This, coupled with, wildcard action mapping allows to be very concise in struts.xml.




But, when I read about the validate() method in the Action class, I couldn't find a way to have a custom validate() method for each of the action. Needless to say, the inputs for each of the actions is going to be different, and thus the validation also will be different. But, I have only one validate() method. Does this mean that I have to do an if/else on the action name in the validate() method?
I've searched Struts FAQs and this forum but couldn't find any relevant information. I'd appreciate it someone can shed some light on this.
7 years ago
Hi,
I have a question about the benefit of putting a web server in front of the app. server. How useful is it, to configure the static content(.gif, .css, .html etc.) to be served up by the web server, forwarding all the requests for dynamic content to the app. server? Yes, there's bound to be 'some' benefit, but are there any published results that quantified this benefit? Will the benefits be more than 5%?
11 years ago
Thank you. I overlooked that method.
11 years ago
JSP
Hi,
I need to construct a fully qualified URL in my JSP, to redirect the client to a page which could be on the same server or on a different server.
Is there a direct way to get the protocol(http or htttps) of the current request ?
I've tried a couple of approaches:
  • request.getProtocol() - returns the string HTTP/1.1. I cannot use this string in my URL, without some kind of string manipulation.
  • request.getURI() - gives me the protocol being used (http:// or https://), but again, I cannot use it without string manipulation.


  • It feels like there should be a simple way to get the protocol of the current request and use it to construct a new fully qualified URL. Any help would be appreciated. Thanks.
    11 years ago
    JSP
    Makes sense. However, why can't we arrange the data so that it's first sorted by one column, and then by the other? I'll consider the simple case of defining clustered indices on last name and first name. If there are any collisions in the last names, the data could then be ordered by the first name:

    Last Name First Name
    ========= ==========
    Adams John
    Bush George H.W.
    Bush George W.
    Clinton William
    ....... ........

    etc.
    11 years ago
    This question has nothing to do with Java, but it's an interview question - I hope this is the right place. Here's the question:

    In SQLServer, you can define a Clustered Index on a Database Table. (For those unfamiliar with what a clustered index is...A clustered index guarantees that the data in the table is ordered per the values in the column(s) that form the clustered index). Can we or can we not define more than one clustered index on a table? Why?

    I know the answer is no. We cannot define more than one clustered index on a table. I couldn't come up with a good answer for the why part of it. Any help?
    TIA.
    11 years ago
    Thanks for your responses. Jim, I tried to paste here some thing you wrote.

    O(n) to check the contents of the second



    My understanding is that with a HashSet/Hashtable, lookup operation is O(1) (for most cases). Can you please elaborate on why you think it's O(n) for the look up on the second array?
    To be more specific, if we do an O(1) operation n times, will the complexity be the same as O(n)?
    11 years ago
    I was asked this question recently in an interview. The interviewer wanted to know how to get the intersection of two unsorted arrays. My answer was to use the brute-force approach - for each element in one array, check if the element exists in the second array by looping thru it. He asked for a better approach, and my answer was to construct a binary search tree using the first array and do a look up with the elements in the second array. He didn't seem satisfied. Are there any better ways of doing this? TIA.
    11 years ago
    Thanks for your reply and for the note about wait vs. blocked.
    Say my class has a synchronized method and one thread is executing the method. A second thread that tries to execute the same method has to wait until the first thread completes. Now, after the first thread is done executing the synchronized method, will the second thread be notified automatically? Or, do I have to explicitly notify() at the end of the synchronized method? If it happens automatically, then what purpose does the wait()/notify() mechanism serve?
    Jeff, I can't believe you do that(PB and pickle) too . We do it all the time. In fact, I even mix some pickle in the alfredo sauce pasta that I order from Chili's and it's really great.
    11 years ago
    No Responses! . I was curious about how Javaranch handles this and hoped that the moderators would know the answer to my question and respond.
    12 years ago
    JSP
    I noticed that if I try to respond to a post without logging in, Javaranch redirects me to the login page, and once I login, takes me back to the original page I was on, before logging in.
    One approach I can think of to do this, is to examine the session for the user's credentials, and if the user has not logged in, redirect him/her to the login page, with a query string that gives the value of the page the user should be sent to, once he/she logs in. But, there has to be a better way of doing this. How does Javaranch do this?
    12 years ago
    JSP
    You could get the RealPath of the image using the getRealPath method in ServletContext class. That path can be used to construct a java.io.File object and you can call the exists() method on that File object, to see if the image exists. There may be better and simpler ways of doing this.
    12 years ago
    Thanks Ilja. Will certainly read Liskov Substitution Principle.
    Garrett, one question about a static method in the child class 'hiding' the static method with the same name in the parent class.

    The following code:

    executes the static method in the Parent class, NOT the static method in the Child class. So, how exactly would a child class static method hide the parent class's static method?