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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 506
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: 60774
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where to put this source code ? *.java or *.jsp
 
Similar Threads
Internal Error while Validating username and password
jsp postgress connection
need help
HttpClient- username and password error.
user authentication servlet problem