Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Boresm Borest
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 524
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, that's an easy one. No code ever goes into a JSP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic