• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Passing values with forms to servlet.

I know how to pass values with a form to a direct JSP example ('www.website.com/index.jsp'). But, I have a servlet that is called ('www.website.com/servlet/test') that actually runs code in the directory ('www.website.com/jsp/code.jsp'). The only way to call is using the servlet, you cannot go to www.website.com/jsp/code.jsp to run it, it must be called using the servlet.

Can you post to the servlet?? or do you need a direct link?
0
kak39
Asked:
kak39
  • 3
  • 3
1 Solution
 
colr__Commented:
You an both POST and GET a servlet, with variables.

colr__
0
 
kak39Author Commented:
Is there anything special I need to do in my servlet code to recieve it properly? I tried just posting to ''www.website.com/servlet/test' and it didn't seem to work.
0
 
kak39Author Commented:
Is there anyway you could just post to a domain? and then anything in that domain can read your POST??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
colr__Commented:
Afraid not - if you post to a domain, you will end up posting to the root file of that domain, usually index.jsp or something like that.

In your servlet, use the following to get the arguments posted:

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

colr__
0
 
kak39Author Commented:
Once I do that can I set that Parameter as a Session Cookie/variable? And how woudl i do that?
0
 
colr__Commented:
Yup, use the folloiwg to set your cookie:


       Cookie cookie = new Cookie("name","value");
       response.addCookie(mycookie);

colr__
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now