0

I am including a jsp file more than once on a single page. I have duplicate html on my page which is why I'm using jsp includes.

I have two input fields in the included file. Is there a way to pass different element id names for each included file?

So to summarise: - Two jsp includes both requesting example.jsp - Two input fields in example.jsp - Find a way to pass two unique element id names for each include

Malcr001
  • 8,179
  • 9
  • 44
  • 57

1 Answers1

0

You can save different value/identifier/flag in session before including two different jsp files

Aneeq Anwar
  • 1,282
  • 7
  • 20
  • The jsp included files are the same. I should also note that I am totally new to jsp and I'm simply using it as a way to avoid duplicated HTML so my knowledge is almost nothing so any example would be a huge help. At the moment I'm using <%@ include file="example.jsp" %> but obviously I'm not parsing a variable with this. – Malcr001 Jun 15 '13 at 20:12
  • 1
    do this <%@ include file="example.jsp?id=1" %> for 1st include and<%@ include file="example.jsp?id=2" %> for 2nd include Then, get this id like this String id = request.getParameter( "id" ); – Aneeq Anwar Jun 15 '13 at 20:13
  • The server reports a 500 not found when I add ?id=a at the end of the file name. – Malcr001 Jun 15 '13 at 20:22
  • 500 error code is not due to your code/programming error http://www.checkupdown.com/status/E500.html http://pcsupport.about.com/od/findbyerrormessage/a/500servererror.htm – Aneeq Anwar Jun 15 '13 at 20:26
  • The above seems like a good way but due to the 500 problem is there another way to do this? – Malcr001 Jun 15 '13 at 20:35
  • Clear the history and caches of browser, and clean and rebuild the project, and then run it, may b 500 error resolve. There can be other way to do this, but it depends on your code, it will be helpful if you share your code – Aneeq Anwar Jun 15 '13 at 20:39
  • I did the above and no change. I cant post the back-end code because its not mine I'm simply handing the front-end side of things and have been using includes to avoid duplicate HTML. Is there no other way to do this? – Malcr001 Jun 15 '13 at 20:53
  • you can save the attrbute id as 1 in session before the 1st include <%@ include file="example.jsp" %> and you can save the attribute id as 2 in session before the 2nd include <%@ include file="example.jsp" %> – Aneeq Anwar Jun 15 '13 at 20:59
  • I instead decided to tackle the problem using javascript which solves the problem for me. Thanks for trying to help. – Malcr001 Jun 15 '13 at 23:42