This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

UploadController suddently stopped working  RSS feed

 
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I don't know why, but suddently I can't upload any files anymore, yesterday averything was working great.
I wasn't even working on that controller, I did however changed my jsp a bit, but that shouldn't be the problem.
Now whenever I try to upload a file, I get a 404, what normally happens when there isn't a controller to handle the requested url or the jsp returned couldn't be found.
Neigther is the case...
Anyone an idea what might be causing this?
My UploadController:

My jsp:
 
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SHow us the html as it appears on the client, as well as the request made (you'll need to get the browser tools up for that part, F12).

That will show us exactly what is happening on the client and what it is trying to access.
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear, this isn't a restApp, it has an MVC architecture.
I included a demo, you can't see anything on the browserconsole, nor are there any errormessages, but I included it anyway.
 
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A 404 isn't that a Controller cannot be found. You only get a 404 when the URL cannot be mapped to a resource. The resource mapping is done via a servlet mapping in the web.xml file and for JSPs and fixed resources by mapping the resource path part of the URL to its path inside the WAR. Note that JEE allows the "web.xml" to be mapped in annotations instead of always requiring a full and discrete web.xml file.

So you've broken your link between source URL and the servlet that manages your UploadController. Check your mappings. Also make sure that the URL is actually pointing to the webapp you think it is on the server you think it is and that the webapp has been successfully deployed on that server.
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use springboot, so there is no web.xml
 
Tim Holloway
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I use springboot, so there is no web.xml



There's always a web.xml. The question is whether you code web.xml as a discrete file or not. Originally web.xml was only a discrete file that was digested and used to configure/deploy the webapp, but JEE added the ability for the server to build up web.xml elements directly in memory by scanning annotations. The server won't care which way you did it, although if there's a conflict, a discrete xml wins over annotations.

In your case, lacking a discrete web.xml file means you need to check your annotations. And, as I mentioned earlier that you are actually talking to the app you think you're talking to!
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't code one is what I ment,
SO apperently it's not calling the expected controller.
How do I fix this, I never came accros such an issue...
Is web.xml created dynamicly?
The reasson I ask is because I moved the controller to a seperate package, is the web.xml being updated or will it still hold the old value? Cause that would explain it
 
Tim Holloway
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as I said, the "real" web.xml is what you get when you read the actual web.xml file file and digest it into internal server objects. In JEE, it's actually more like first an in-memory web.xml is built by scanning the annotations, then the web.xml file (if it exists) is read and applied over what was already built. Actual details may vary, but that's the net effect.

If you moved the controller to a separate package, chances are that its resource path changed to reflect the new package path so you need to either change the URL you're using or maybe define an override to the new default URL in another annotation. I'm not familiar enough with the stuff you're using to be able to tell if that second option is available.
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When thinking about it dosnt really make sence that changing the package would cause the  issue, since the getmethod in the same controller is still being called
 
Tim Holloway
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:When thinking about it dosnt really make sence that changing the package would cause the  issue, since the getmethod in the same controller is still being called



Well, your client doesn't "call the Controller". It submits a URL request. If the app doesn't have a mapping from that URL to your Controller, the Controller won't get called. What I'm saying that that the URL for calling that Controller probably has the package name as part of its resource path and when you changed the package, you changed what it thought the resource path should be to match the new package path.
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no packages included in the url, both get and  post are mapped to /upload
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but you're right. It's the mapping, I tried to use a redirect instead of returning the jsp directly and then the get method also fails...
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could the issue be that I'm using a button (so a form with a getmethod) to open the filechooser and then again a form to submit the file, cause when I change the method to open my filechooser to a post, the correct method is called which results an in error of course, since it's not a multipart request and that's what the method expects... If so how to fix this? I already tried to not use a form but open the fileselector with javaScript but the result was the same
 
Tim Holloway
Bartender
Posts: 20307
110
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't understand that at all.

To upload a file using the HTTP protocols, you must POST a form of type mime/multipart. The multipart is because it's not just sending data, but also other parts too. Most obviously the upload filename, whether you use it or not. The server cannot suck data out of the client - it's physically impossible. So the client has to push the data to the server. This "push" is a builtin component of an HTML file upload on the client.

Now it's time to issue my customary warning that Web servers are not File servers, so you can't actually "copy a file" from client to server in the usual sense. Instead you have to make a URL request where the data from the file is the request payload.

If you POST a FORM, then the server will route the data stream to temporary storage. It might be in RAM, it might be in a temporary file. Doesn't matter, since the only way you can obtain the content - and, for that matter - the other mime parts - is to use the upload API. You can then copy the data to a file, a database, wherever, even eat it on the fly and discard it.

Alternatively, client-side JavaScript, Java applets, and other such client-side logic can simply post the content as raw data copied without the other MIME parts, in which case the server will simply see it as data with no filename or other attributes. That's of course, assuming you've relaxed the sandbox rules, since ordinarily applets and client JavaScript are prohibited from opening and reading files at all.
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem isn't the mapping, it's that stupid enctype="multipart/form-data".
If i remove the parameter from my method, comment out the file handeling in my controller and remove the enctype from my form, the right controller is being used, of course the the file isn't prossed, so it's useless, but at least I know now that's not the mapping
 
Daniel Demesmaecker
Master Rancher
Posts: 1042
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OMG... I've could have bin searching for ever... I was looking in the total wrong place... The problem was that I was using csrf protection...
 
Dave Tolls
Master Rancher
Posts: 3887
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Just to be clear, this isn't a restApp, it has an MVC architecture.
I included a demo, you can't see anything on the browserconsole, nor are there any errormessages, but I included it anyway.



?

Even an MVC architecture will show you what is being built in the browser.
It's still HTML.

It iwll also still show you what calls are being made from the browser.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!