my dog learned polymorphism
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

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

Boresm Borest

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

if (request.getMethod().equals("POST"))
String userID = request.getParameter("username");
String userPWD = request.getParameter("password");

String data = "username=" + userID + "&password=" + userPWD;
String link = "" + data;
URL url = new URL(link);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 524
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

Joined: Jan 10, 2002
Posts: 63858

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

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Where to put this source code ? *.java or *.jsp
It's not a secret anymore!