2

I'm sorry for my english. I have a parameter in my jsp named action I get it and put it in an another parameter named also action because i need it in my servlet

<input type="hidden" name="action" value="<%request.getParameter("action"); %>" />
<input type="submit" value="Suivre" />

So when I print this: <%out.println(request.getParameter("action")); %>. i got the value, but in the servlet the result is like this: String action ="";

String action = request.getParameter("action");

where is the problem?? thanks

Edit: as @arjuncc and @Neuron says i change it to value=<%=request.getParameter("action")%>, it works but I have an / added in the end of String action, I will use subString for that and it WORKS, Thanks every body, specially @arjuncc and @Neuron

Wanna Coffee
  • 2,742
  • 7
  • 40
  • 66
user3041570
  • 21
  • 1
  • 4

5 Answers5

2

I Strongly suggest you to use Expression Language , There are many problems with using scriptlets like

  • Reusability: you can't reuse scriptlets.
  • Replaceability: you can't make scriptlets abstract.
  • OO-ability: you can't make use of inheritance/composition.
  • Debuggability: if scriptlet throws an exception halfway, all you get is a blank page.
  • Testability: scriptlets are not unit-testable.
  • Maintainability: per saldo more time is needed to maintain mingled/cluttered/duplicated code logic.

The problem with your code is that, you have used the scriplet <% %> in your code, which suppose to provide the ability to insert java code inside the jsp. In order to print something in your page you have to use the JSP expression tag <%= %>

<input type='hidden' name='action' value='<%=request.getParameter("action") %>' />
<input type="submit" value="Suivre" />
Community
  • 1
  • 1
arjuncc
  • 3,227
  • 5
  • 42
  • 77
1

In general scriplets should be avoided. Use JSP EL:

<input type="hidden" name="action" value="${action}" />
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • I'm learning JSP so tell now I still do know nothing about EL – user3041570 Jan 22 '14 at 11:10
  • I mean I'm a beginner, I know that they are JSP but I still didn't got that far – user3041570 Jan 22 '14 at 11:20
  • 1
    The beginning is the best time to learn best practices. Why don't you try making a GitHub Gist that contains the pertinent files you are using such as web.xml, .jsp files and any servlets. This will help others answer your question. – Kevin Bowersox Jan 22 '14 at 11:24
0

In first look

change the below

"<%request.getParameter("action"); %>"

to (without quote)

<%request.getParameter("action"); %>
A Paul
  • 8,113
  • 3
  • 31
  • 61
0

You can use JSP expression <%= .... %> note = after % (Not recommended way)

<input type="hidden" name="action" value="<%=request.getParameter("action"); %>" />

Do not write scriptlets in JSP, because scriptlets shouldn't be used in JSPs for more than a decade. Learn the JSP EL, the JSTL, and use servlet for the Java code. How to avoid Java Code in JSP-Files?

<input type="hidden" name="action" value="{param.action}" />
Community
  • 1
  • 1
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
0

You better use <%=request.getParameter("action")%> instead of <%request.getParameter("action")%>.

Devavrata
  • 1,785
  • 17
  • 30