Pass Parameter from jsp to java

by Mohan 2014-02-15 14:12:47

<h1>
Pass Parameter from jsp to java
</h1>

Sample code to pass parameter from JSP to JAVA class file

<h2>Java File</h2>


package HelloWorld;
import java.io.*;
import java.io.File;


public class HelloWorld extends HttpServlet {


public String sample(String myfolder){

File f = new File("/opt/lampp/htdocs/test/"+myfolder);
Boolean t= f.mkdir();
if(t)
return "folder created";
else
return "folder Not created";

}

}


And here is JSP code

<h2>Jsp File</h2>


<%@ page language="java" import="HelloWorld.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
HelloWorld hm = new HelloWorld();
String inputvalue = "super-folder";
String output = hm.sample(inputvalue);
out.println(inputvalue);
out.println(output);%>
</body>
</html>




Execute the jsp file in browser,the file will pass inputvalue as argument to HelloWorld java file by calling sample(inputvalue) function.

Tagged in:

1041
like
0
dislike
0
mail
flag

You must LOGIN to add comments