0

I am trying to fix a set of buttons on a JSP page in a Spring MVC framework.

Currently, the link when clicked will cause the URL to look like something akin to

localhost:8080/DADA/servlet/page1?id=92

I need everything after the question mark removed. Can I do this all from the JSP/HTML page, or do I need to go into the controller and change things at that level?

currently it is setup as

<spring: url var = "var1" value="${servletPath}/page1">
<spring: param name="id" value= "${id.id}" />

The answers linked showed a hardcoded variable for the URL that was placed into a JS function. This one is specifically written using spring:url with a separate parameter tag being passed in.

Jack Parker
  • 547
  • 2
  • 9
  • 32
  • You can do it using javascript. Refer to this question http://stackoverflow.com/questions/6257463/how-to-get-the-url-without-any-parameters-in-javascript – J28 Sep 17 '15 at 18:27
  • possible duplicate of [Remove querystring from URL](http://stackoverflow.com/questions/2540969/remove-querystring-from-url) – StackFlowed Sep 17 '15 at 18:28
  • OK, so I'm a tiny bit confused here. Do I take the spring url I've written, pass it into a javascript function, split it, and return it? – Jack Parker Sep 17 '15 at 18:44
  • 1
    *Why* do you need this? I've got the feeling that we cannot help you successfully if you don't indicate your intent. – Maarten Bodewes Sep 17 '15 at 20:05
  • I was told that the parameters needed to be removed from the URL. I have no reason, I've been trying a number of things, but couldn't get it. – Jack Parker Sep 17 '15 at 20:07
  • OK, technically speaking I found a way to remove the parameters. I am using a link, and I've cut the link down to redirect to the page without the parameter, however, without the parameter an error gets thrown at the page. – Jack Parker Sep 18 '15 at 01:56

1 Answers1

1

I haven't touched a JSP in years however it sounds like you want something like this:

<spring: url var = "var1" value="${servletPath}/page1/${id.id}">

In which case your controller will need to be updated to accept a path variable.

@RequestMapping("/page1/{id}")
Foo bar(@PathVariable("id") String id) { ... }
kab
  • 131
  • 4