• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to check if url parameter is present or not in request?  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there

I want to run a function on load only when a particular parameter is not present?

M question is how to detect in JSP that if a particular parameter is present or not?


Thanks
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't have processing logic in the jsp. Do you mean in the servlet? If so, check request.getParameterMap(). There is a function there that will help.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no In my case I have to check them on JSP using some Java Script.

Parameters are passed from servlet to JSP using requestdispatcher
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not going to work. JavaScript doesn't run on the server and it isn't passed the URL or parameters.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok let me explain

this is my servlet code


and this is my .js file



I want to run that resetPage() method when "messages" parameters is not present in URL requeest.

What is now happening in after validating some values from server all values are cleared.

I hope I have clear it all

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're doing it wrong.

As already pointed out, you check parameters in the controller. Why would want to perform these checks in both places? If you want to trigger JavaScript in the HTML page, send a scoped variable that tells the JSP to construct the appropriate JavaScript. You should not be doing checks in the JSP.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Bear Bibeault

can you give any code snipshot?

my requirement is very simple I want to run that function resetpage to clear all values when user press referesh button on browser.Not when request is receiving from some other site like from servlet or other jsp page
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you:
  • Know what a scoped variable is and how to set it?
  • Know how to use <c:if> on a JSP?

  • If so, you know everything that you need to know.
     
    Kishor Joshi
    Ranch Hand
    Posts: 674
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have some knowledge about scopeVariable and also some knowledge about <c:if />

    But how can i use them in y application?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66207
    151
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm not going to do your work for you. but will give you some example hints:

    Setting up a scoped variable in a controller:


    Doing something in a JSP with it:

     
    Kishor Joshi
    Ranch Hand
    Posts: 674
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is more than writing code for me @bear

    You have showed be How to fish...

    This is perfect for me

    Thanks
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66207
    151
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!