• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating a common jsp for many JSPs  RSS feed

 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every body.

i have various jsp pages. which have many things(code lines) common betwwen them.

i am using netbeans. so say every jsp page will have




again if i am including a same file in each JSp page

say file



and many more such things

like including common hidden variable in each page.


i want to create a common jsp for all these and directly use that file instead of writing all these things again and again in each jsp.
how can i imoplement this.
please help.
i tried creating function for each common things say




but this is giving error when iam writing this in my common.jsp.
i am using netbeans 6.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should no longer be using scriptlets and scriptlet declarations in your JSPs. That went out in 2002.

That said, look into preludes.
 
Swastik Dey
Rancher
Posts: 1794
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not write the statements given inside a function, probably what you can do is create a page called commons.jsp like this



now any in page where you want the above functionality just include the file

 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi swastik.

i did what you wrote.

something like this in my common.jsp



i also have a java script function which sets the value of hidden variable userAction .here iam getting the problem.
i am not able to access the variable or not able to set the value.
how can we do that.
 
Swastik Dey
Rancher
Posts: 1794
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats your js code to set the value in the hidden field?
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think the page which is including file common.jsp is not able to access hidden variable userAction which is in common.jsp

i have commented the hidden variable in the file which is including common.jsp.

any solutions.

shall i need to store the contents in a string in common.jsp and access string one by one where ever required in the file which is including it.
 
Swastik Dey
Rancher
Posts: 1794
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//the following is code what you currently have, I just included another attribute as id in the input tag




Following is another jsp page which sets the value in the userAction hidden field



 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my code to set the hidden variable is



here drop_list is the form name.

to test, i just assigned some value "123" to hidden variable userAction in common.jsp.
and before setting the new value to userAction , i am alerting it .. just to check the value. it is giving nothing.

this function ( onSubmitForm) is called whenevr a button is clicked. that is





also my common.jsp has only




no html tag or anything.
just the above text written as it.
it it ok.
 
Swastik Dey
Rancher
Posts: 1794
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its unlikely to work because the userAction hidden field is not inside the form you are referring to, so you might have to use document.getElementById()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!