This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes struts newbie needs help with autocompleter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts newbie needs help with autocompleter" Watch "struts newbie needs help with autocompleter" New topic
Author

struts newbie needs help with autocompleter

Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
Hi all. Im new to struts. I have been reading up on it for about 2 days now. I am trying to get an autocompleter to work from a list populated by a database call. I understand that I can set up a class that adds things to a list. I can handle the database call, no problem. The problem I have is all the config thats required in struts.
Im currently using struts 2.1.
I have the following in my JSP:
with of course the

I also have the following in a class :-


and here's where I think I am going wrong. I have the following in struts.xml:-

and the following in the web.xml:-


but I get the error "The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]"
when visiting my jsp page. So I added the following to the web.xml:-



and then I get a HTTP 404.

Can anyone help. It's frustrating getting started with struts. I get the ideas behind it but cant get anything to actually work.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Mark Wa wrote:

Whoa, that's Struts 1. You'll want to take out all the Struts 1 stuff.

What libraries are you deploying?
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
Does nobody have any ideas?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please read EaseUp. It's 8:30 on a Saturday morning--the weekend.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
My apologies. Its 12.40 here. I forget that most of this forum's users are probably in the USA. I don't mean to be pushy.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
David Newton wrote:
Mark Wa wrote:

Whoa, that's Struts 1. You'll want to take out all the Struts 1 stuff.

What libraries are you deploying?


sorry didn't see your post.
I am using the struts 2.1 jars. I probably mixed up code from head first servlets&jsps as well as demos on the internet. My bad.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
OK. That's Stripped out. Now I guess as i'm still getting a HTTP404 that the filter is not forwarding the request on
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

"The" Struts 2 jars doesn't help.

Please see TellTheDetails.

Is there anything in the startup log? (My guess right now is yes.) Do you have devMode turned on?
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
I added all the jars that came with struts 2 as I am unsure of which I will be needing.

Server log? - yes there's this:- (but it always says this)


dev mode? no idea what that is.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You cannot add an arbitrary collection of jars to a deployment, as each may introduce their own dependencies, or otherwise impact expected behavior. Stick to the minimum until you know what you're doing.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
OK I just have :-

jstl-api-1.2.jar
jstl-impl-1.2.jar
spring-core-2.5.6.jar
spring-web-2.5.6.jar
struts2-core-2.1.8.1.jar
struts2-dojo-plugin-2.1.8.1.jar
struts2-spring-plugin-2.1.8.1.jar
xwork-core-2.1.6.jar

now it deploys fine when I deploy without the filter, but when I add the filter stuff into the web.xml I get an error. My guess is that the jar containing the required class is not there? - googling it but not having much luck.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You can't deploy the Spring plugin without deploying Spring.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
OK. forgetting the spring jars the problem is still the same

The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you calling a JSP page with Struts 2 tags directly instead of going through an action?
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
Yes probably. I am typing the URL of the jsp page with the tags on.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

As the error states, you can't.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
but would



not run everything through the filter?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yes. That does not mean the filter *does* something with every request.

Seriously; why would I lie?
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
David Newton wrote:Yes. That does not mean the filter *does* something with every request.

Seriously; why would I lie?


OK now i'm confused. Think I need to find a comprehensive struts tutorial. Any suggestions?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How about the Struts documentation wiki?

What's confusing? A filter mapped to "/*" will intercept every request. Filters can ignore requests and simply pass it on to the next filter in the chain.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
Yeah I understand the filters bit, just not sure how I should be accessing my jsp
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Through an action.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
and that would be?

http://localhost:8080/mywebappname/autocompleter.action ?
http://localhost:8080/mywebappname/autocompleter ?

nothing works
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

ItDoesntWorkIsUseless.

I don't know what the app context is you're deploying to; if it's "mywebapname" as you imply then either should work with Struts 2.1.

I'd encourage you to turn on devMode, set the log level to debug, and look for startup errors.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
wow you have tips pages for everything!

It works (well not correctly, but IT WORKS!)

I changed both of these from false to true


Nearly a whole day, but Its solved!

Thanks David for your help. Its much appreciated.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

DynamicMethodInvocation is something else entirely and would not have caused it to start working; it's only for using "action!method" URL patterns. DevMode just jacks up some reporting. If it started working after those changes then something else had been corrected, but not deployed.

No problem--it can be a frustrating process wrapping your head around something new sometimes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: struts newbie needs help with autocompleter
 
Similar Threads
Need Help - Struts2 s:select issue - Urgent
Velocity + Struts2 + Sitemesh + Spring +Hibernate Integration How to configur web.xml?
Autocompleter
Struts and AjaxTags autocompleter
struts2 jquery autocompleter