Jim Gmeiner

Greenhorn
+ Follow
since May 02, 2012
Merit badge: grant badges
For More
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 Jim Gmeiner

Ok, making progress albeit slowy. My problem now is I want the results showing up in original jsp (index.jsp) as opposed to the jsp that I currently 'forwarding' it to (searchResults.jsp)

Here is the code that I added to 'searchResults.jsp':



Here is the code for index.jsp:



Now lines 1 & 2 from searchResults.jsp were inserted after Line 1 in index.jsp, and Lines 14 - 25 from searchResults.jsp replaced lines 53 - 60 in index.jsp.

Now what is happening is this:
1. I run my jsp form
2. I enter text into one of my 6 text boxes and hit the "Submit" button
3. The program crashes with a "Null Pointer Exception"

Now I know, I know, I know from reading other posts that Java code in the jsp is frowned up, but I have been told that is how I have to do it (reasons unknown).

With that said, I'm thinking that the reason for the "Null Pointer Exception" is because when I do the getAttribute it comes back null because I haven't done the setAttribute because the servlet hasn't run because I haven't hit the "Submit" button yet. (enough "because's" for one sentence?)

Should I be checking the "items" object for a null value first and then skipping the "for" statement if it is null?

Thanks to anyone who has time to respond to this post.
11 years ago
JSP
You are correct. "skusearch" probably isn't the best name, but I'm flying by the seat of my pants right now.
11 years ago
JSP




My issue now is that I am trying to pass a collection list object to the JSP, but I'm not sure how to reference the list object after it has been 'forwarded' back to the JSP.

This is my code on the JSP:



Eclipse is yelling at me saying "Syntax error on tokens, delete these tokens"

I am using the JSP 2.0 method, I found the information below from a PDF document.

• Servlet
SomeBean value = LookupService.findResult(...);
request.setAttribute("key", value);
RequestDispatcher dispatcher =
request.getRequestDispatcher
("/WEB-INF/SomePage.jsp");
dispatcher.forward(request, response);
• JSP 2.0
${key.someProperty}
• JSP 1.2 (Old!)
<jsp:useBean id="key" type="somePackage.SomeBean"
scope="request" />
<jsp:getProperty name="key" property="someProperty" />



Bear, You mentioned using JSTL and EL notation tags. How would these tags look when looping through list object on the JSP?

Thanks,


11 years ago
JSP
Thanks Bear. I think that my confusion now is with the 2 JSP files. Does the 2nd JSP file(results.jsp in my example), the one that receives the data forwarded from the servlet now become the interface for my user?

You see I still have procedural mindset while approaching this problem. I think of the first JSP as my interface to the user, it calls the servlet which does my processing and then sends the data back to the calling JSP which would create my table and allow the user to select another field to do another search on if desired.

By sending (forwarding) the data to a different JSP, is my user now looking at a different page now, and how does the user go about performing a new search?

Thanks again for your advice.

11 years ago
JSP
It is good to know that there is a friendly place for a Java greenhorn like me. I have an assignment where I need to create a Java screen to interface a file on an AS/400 / iSeries system.

I have created a JSP called test.

Now This JSP calls a servlet called ProcessSKUSearch.java The code for that looks like this:
package com.mscdirect.test;





What I have been doing for testing purposes, is creating a table on the servlet to display the results of an SQL statement. What I need to do is forward these results to another JSP. I have been working with a Java developer who is very limited in his time for me. He suggested that I modify the above servlet code to use RequestDispatcher.forward and the setAttibute method to accomplish this. I have studied some examples, but I don't understand what I am actually sending this new JSP (Lets call is results.jsp), or what it is suppose to do with what I am sending it.

Thanks to anyone that can help me,


BTW, is it possible to add/paste a screen from another browser page to this post? I tried doing it, but it wouldn't paste the screen.






11 years ago
JSP