How to pass information from a JSP page to a Servlet

Asked

Viewed 713 times

2

I need to pass information from a String variable that is on a JSP page to a Servlet. For example:

String path = "C: test.jpg";

How do I get this information from Servlet?

  • I imagine you send this information via url(get) or form(post normally), that’s right?

1 answer

3


To get the value of a form field or parameter value of a query string, use the text getParameter() of the object request.

url: www.teste.com? parameter=test

How to get the value in Servlet:

String param = request.getParameter("parametro");

If the value is an integer or another type, a type conversion will be necessary, because the http protocol only works with text, in other words everything is a string.

  • This value of the String that you pass to my Serrvlet will not be sent by my form because I will determine what will be the String and not the user, it is possible to pass the information of the string without being by a form?

  • @R.Santos you can send by form with a field Hidden, this will not be visible to the user.

  • And what that would be like Hidden=<%=param%>?

  • @R.Santos, <form action="sua action"> <input type="hidden" name="param" value="C:\teste.jpg" /> </form>

  • Perfect, it worked well. Thanks for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.