Peter Maxwell

Greenhorn
+ Follow
since Jun 14, 2009
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 Peter Maxwell

Sebastian Janisch wrote:Every JSP page gets translated into a plain old Servlet by the container.
So, even if your JSP contains only static html content, the container couldn't care less :-) .

In case you care to see what the JSP is getting translated to, check the 'work' directory in your Tomcat installation folder.
Watch out though, it's getting messy



Thanks .
Heh,And I thought that the container would be smart like an optimizing compiler.
12 years ago
JSP
Hello Everybody,
Suppose if i have a static html page named with extension .jsp will it affect the time for retrieval of the page?
Or would the container simply treat the jsp as html in that case?

Thanks.
12 years ago
JSP

Bear Bibeault wrote:It is customary to place JSPs under a folder within WEB-INF. There, they cannot be served directly and can only be accessed via a forward from another resource (such as a servlet).



Thanks a lot sheriff!. I didn't think the solution would be that simple.
12 years ago
JSP
Hello everybody,
I have the following scenario:
1)I have a jsp A.
2)Jsp A submits to a servlet B.
3)Servlet B checks the request parameters with the database and decides whether to forward to jsp C
4)If required conditions are not satisfied in 3, the user is redirected to an html error page.

Now the problem is i don't want the user accessing the jsp C directly with its url but access it only via the servlet.
If the user tries to access the page C directly, then he/she should be redirected to a page which shows the access is invalid.
How can i implement this?.
Any ideas would be much welcome.
12 years ago
JSP

Bear Bibeault wrote:Even if it weren't the case, again, using a JSP to collect the data and then forward to a servlet is just bizarre.

In any case, check out BeanUtils.populate() to get the same effect.



Thanks, I'll check that out and post back if i am stuck.
Thanks again for your time.
12 years ago
JSP

Bear Bibeault wrote:It is not proper. As pointed out, submitting to a JSP just so you can use the old-fashioned setProperties tag is just awkward.

Submit to a servlet and grab the values from the request and set them into the bean in Java code. if you would like "bean assist", check out the Jakarta commons BeanUtils project.



Thanks for replying Bear Bibeault.
I checked the commons BeanUtils project.
The setProperty method provides a way to set the properties of the one by one. But the setProperty tag allows to set all the properties at one go using attribute property="*" .
Is there any method which allows me to do the same?. Or is it the case of tradeoff between convenience of developer vs maintainability?
12 years ago
JSP
Hello everybody,
I need to insert a record into a table. I do the following currently,
1)Get the values of input fields from the form of jsp(say, A)
2)Submit them to another jsp(say, B)
3)In jsp B, i use the jsp:useBean and jsp:setProperty to send the values to a bean.
4)Now I forward from jsp B, to a servlet C.
5)This servlet receives the bean and uses an ordinary java class which creates connections and
insert the members of the bean to a table in database.

Is the above correct way to do this?.
Some one here pointed out that submit to a jsp is not a proper way to go in another thread.
Does all the steps above are necessary to insert a record to a database?
Can i use a servlet instead of a jsp in step 2? Is there any equivalent for jsp:useBean and jsp:setProperty in servlets?
Any good alternatives there?
12 years ago
JSP
G'day everybody,

I have a database table with fields product,manufacturers and suppliers. I am using a bean which returns an ArrayList of these values which i am using to display the table in a jsp. Now i would like to have another jsp which generates a 10x3 table of cells having input fields(text boxes) in which i would enter these values(product,Manufacturer,supplier) and submit them to the database.
My problem is how would i go about naming these 10x3 input form fields?. For getting the data from the bean i use ArrayList which contains the ResultSet. Similarly how can i submit them to the database using a bean?. Is there any standard way to do things like this?.

After hours of work,I am completely stumped at this . Any help in any form(links, suggestions)would be very much appreciated.

PS:
I am using eclipse ganymede IDE to develop my program and the following line of code

gives me a warning "Array List is a raw type.References to generic type ArrayList<E> should be parameterized".
How can i remove this warning?

Thanks in advance.

Bear Bibeault wrote:First, why share the controller in this way? Why does each page not get its own controller? Do you have a good reason for the sharing?

Secondly, it's a bad idea to switch based upon implicit information such as where the page came from. This makes you code tightly coupled and fragile. Better to use explicit information such as a parameter.


Thanks Bear Bibeault for replying.
Well I thought it(sharing the controlloer) might save code and extra file for another servlet. Other than that i don't really have a good reason. So i'd be better off with a separate controller i guess.


Alternate ways:

1.QueryString parameter

2. wild card servlet mapping


Thanks Seetharaman,
I tried googling those terms but i couldn't get any pages explaining them.
Could you explain what they are?
Thanks.
12 years ago
JSP
Thanks seetharaman and harilal for quick replies.

seetharaman venkatasamy wrote:

Peter Maxwell wrote:
Is this possible/good idea?



Possible . It is not a bad idea, since servlet is a good controller. and you need to check the input parameters(which are from the jsps) in servlet using else if or switch



Is checking the input parameter is the only way to determine the source of the request or is there any specific method to do this?
I can always use a hidden parameter to differentiate between two pages when they have the same type/number of parameters(or both have no parameters) but it would be nice to know if there are any method specifically to deal with this.

Thanks again.
12 years ago
JSP
G'day everyone,

I have four jsps say A,B,C,D and a servlet E.
I would like to have the servlet E display the page C if the request came from page A and page D if the request came from page B.
Is this possible/good idea?
If possible, is there any method available which can tell the servlet from where(which page) the request came?
If not/bad idea, what would be a good alternative?
Thanks.
12 years ago
JSP

Bear Bibeault wrote:

Peter Maxwell wrote:
Well that's so embarrassing , as i've always called it that way.

It's a common nomenclature usage that somehow got started. No need for the red face.

Thanks, that looks like a simple and elegant solution for this and that solves my problem.


Just basic HTML.

But just out of curiosity is there anyway that EL can do this?


Not on its own. Remember, the EL is purposefully hobbled to only allow display type interaction as a way to dissuade people from doing non-view calculations in JSPs. However, the fn class of EL functions in the JSTL allow a certain amount of string manipulation. But again, it should not be misused for data processing.



Thanks a lot for your time and help, Bear.
12 years ago
JSP
Thanks Bear Bibeault for the quick reply.

Bear Bibeault wrote:Welcome to the Ranch.

A couple of things:

It's not a "combo box", no such control exists on the web. Please read this for more information.


Well that's so embarassing , as i've always called it that way.


Bear Bibeault wrote:
Secondly, rather than trying to parse out part of the display value, use the value attribute on the option elements to submit extactly what you need and nothing else.


Thanks, that looks like a simple and elegant solution for this and that solves my problem. But just out of curiosity is there anyway that EL can do this?

Bear Bibeault wrote:
You might also want to read through this article to find out why submitting directly to a JSP is not considered a best practice.


Thanks for the link. I'll go through that.

12 years ago
JSP
Howdy fellas,

I have a combo box which might take values like
1.Orange
2.Apple
in my "index.html" file which I submit to "GetList.jsp" file.

Here at "GetList.jsp", i would like to have only the part of the "fruit" param (viz., the number 1,2,etc.,) and not the whole thing ("1.Orange","2.Apple",etc.,)
which i submit to another jsp as a hidden param like the code below:


But the code above makes use of expressions which i learnt is bad as scripting should be avoided in jsp.
So is there a way, i can do the same thing using a EL.
${param.fruit} gets me the whole value. How can i get part of it?

Any help would be appreciated.
Thanks.
12 years ago
JSP