Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
public class Hello{

String str="";
public static void main(String []args){


}
}
//This is my view

<html
<body>
<input type =text name="urltext">
<input type="button" name="btn">
</body>
</html>

My question is when i click the button What i given in textbox it will assign to String str.Please help me out.
Posted
Comments
Shubhashish_Mandal 7-Jul-13 5:12am    
How it could be possible for the Hello class. This class is not a servlet or anything that can process the request. Did you use any framework? It's just a simple java class and you didn't give the class any power to handle the request. To read the value you need to create a web application.
[no name] 7-Jul-13 7:36am    
add a setter and getter method to the class, and in jsp try to use the hello class as bean, simply set the str var using setter and getter methods :D
chinta123 7-Jul-13 14:48pm    
can somebody please give me an example?

1 solution

use scriplet (i.e <%%>) for writing java code in jsp page

XML
<html
<body>
<form method="post">
<input type =text name="urltext">
<input type="Submit" name="btn" value="submit">
<%
String txtbox=request.getParameter("urltext");
String btn1=request.getParameter("btn");
if(btn1!=null)
{
    out.println(txtbox);
}

%>
</body>
</html>
 
Share this answer
 
Comments
Member 13598702 9-Jan-18 2:10am    
how to send testing ,"testing" testing testing testing testing testing value jsp
Member 13598702 9-Jan-18 2:11am    
string value with ' or " cannot be retrieved in java

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900