Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

POSTing to login to Server :from JSP or a specific Servlet file?  RSS feed

 
c orange
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Do i do this in JSP(which works but...) or from within a Servlet?

when i do the following in my .jsp file :

<form action="https://abc.def.com/servlet/ServletLogin" method="post">
username : <input type="text" name="username" size="20">
password : <input type="text" name="password" size="20">
<input type="submit" value="Submit">

the response object came back to be a display of the page after logging in. but how do i pass this object to a servlet to process?

or have i done it all wrong and the above "post" should really only be done in a e.g. ConnectServlet.java file?

please advise.
thank you.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I donĀ“t understand you.

Please elaborate in detail.
 
c orange
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yikes, sorry.

ok, i am trying to create an app that can connect to 2 external and separate servers.
so, do i start the connection with a jsp file or a servlet file.
so as in my first email, if i need to connect to a specific https:// url using the post method, and passing
in the 2 parameters required to get past the login page, should i do this from a .jsp file?
or should that be done in a .java(extend httpservlet) servlet file?

so far, i did that POST from a jsp file and what got returned was the after-login page. but i don't know how to manipulate it(as in can't pull out sets of data) since it's come back as a web page. so was wondering if i did this POST(and i don't know how) in a GoConnect.java file extending HttpServlet then, manipulating the returned object would be easier/possible?(especially with the API provided)

hope i'm making sense ?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if I can follow you.

But you normally write HTML (e.g. <form>) in a JSP file and you normally write Java in a Java class (e.g. a servlet).
 
c orange
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


so if you're creating a java web app to connect to a server hosted somewhere,
will you use a jsp(like what i did) to call a connection to the server or the java file?

or do people just not do that? and i've completely misunderstood how it all works?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the language you're using for this. If it is plain vanilla HTML (e.g. <form> or ), write it in a JSP file. If it is raw Java code (e.g. java.net.URLConnection), write it in a Java class. That's all.
 
c orange
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sorry,think i haven't been clear:

i want to make a connection to a server hosted somewhere.(in java)

is there a conventional or "correct" way to go about this?
do i connect(do the posting/getting etc) using a JSP (form action, method, parameter etc)
or do i connect(posting/getting using httpURLconnection etc) using a servlet ?

upon successful connection and login i will need to use the API provided to call methods to return datasets you see.

i know that html tags etc goes into a jsp and java code goes into a java class, but that's not what i'm asking.

thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are posting a form to another server. What do you want to happen to the response returned by the other server?

Do you want it it displayed in the browser? Or do you need to process it yourself in your own code?

Without such details, no answer is possible.
 
c orange
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

yes! that's it!
i need to do exactly that and nope, not to display in a browser(yet) but to process what's returned in my own code

so this processing of what's returned, i'm guessing that's easier done within a servlet than a jsp right?

so hopefully the following details are enough for you to direct me:

1) post form to another server(from jsp or from servlet? what's the right thing to do?)
2) get what's returned, need to process it in my code(sift out what's not wanted)
3) and THEN display what's processed(in browser)

fullstop!

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!