I'm new in using JSP and I need to get a value from a textbox by upon clicking a button. I am using Java Netbeans with the server apache tomcat. This is how it works...
The textbox is enclosed in an HTML tag <table>
once the user inputs a value, he clicks the button then a message box will appear with the value he entered.
I am not familiar with JSP and it gives me a hard time.
You need to configure a servlet in web.xml
Create a form and post the date to that servlet
Here I have outlined how it should look
Your JSP
<form action"/yourServlet" method ="post">
<input type="text" name="age"/>
<input type="SUBMIT" />
</form>
Your Servlet
doPost(....){
String age = request.getParameter("age");
}
Must See
My answer is quite familiar with the first answer.
mainPage.jsp
<html>
<head>
<title>Your Title Here</title>
</head>
<body>
<form action="sample.jsp" method="POST">
<input type="text" id="firstname" name="firstname" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
sample.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%
String firstname = request.getParameter("firstname");
/*
* Some code here
*/
%>
I'm also using apache tomcat.
You have to configure your web.xml as said in the first answer.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With