Results 1 to 2 of 2
  1. #1
    Tores is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Question Where to put this source code ? *.java or *.jsp

    Hi
    I am here not to get help about my source code content itself because it works but I am asking where to put this code ? in the *.java file or the jsp file ?
    If *.java file then nothing easy then copy/past it into it but if it is jsp file so is it just put this code between <% %> ?
    Java Code:
    import java.net.*;
    import java.io.*;
    {
    if (request.getMethod().equals("POST"))
    {
    String userID  = request.getParameter("username");
    String userPWD = request.getParameter("password");
    
    String data = "username=" + userID + "&password=" + userPWD;
    String link = "http://website.com/script.php?" + data;
    URL url = new URL(link);
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    reader.close();
    
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,008
    Rep Power
    20

    Default Re: Where to put this source code ? *.java or *.jsp

    It's code.
    It doesn't belong in a JSP file.
    Since it deals with specifics of a request then it should be in a servlet.
    That servlet will then forward to a JSP after it's finished doing whatever it is it is doing.

    Since servlets have doGet() and doPost() you can even skip the check on request method.

Similar Threads

  1. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  2. How can I get a GUI preview on java source code
    By KevinQ in forum AWT / Swing
    Replies: 2
    Last Post: 06-10-2011, 12:36 PM
  3. java compiler source code
    By vkolluru in forum New To Java
    Replies: 13
    Last Post: 02-24-2010, 07:28 AM
  4. Can we Obtain Java Source Code?
    By tornado in forum New To Java
    Replies: 7
    Last Post: 12-10-2008, 07:23 PM
  5. Replies: 1
    Last Post: 11-28-2008, 06:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •