File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Where to put this source code ? *.java or *.jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Where to put this source code ? *.java or *.jsp " Watch "Where to put this source code ? *.java or *.jsp " New topic
Author

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

Boresm Borest
Greenhorn

Joined: Feb 22, 2012
Posts: 8
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 <% %> ?

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();

}
}
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 512
Java code belongs to java file. JSP falls under view in MVC(Model View Controller) architecture which is used to display the content. Business processing should done in java files.

<% %> using this you can include the same code in JSP file and make it work, but scriplets are not good practice and instead JSTL and EL should be used.

Hope this helps. and Welcome to Javaranch :)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 62275
    
  68

Yup, that's an easy one. No code ever goes into a JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: Where to put this source code ? *.java or *.jsp