yoop

Greenhorn
+ Follow
since May 05, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by yoop

in which method shuld i use at the servlet code for request
the value of a radio button in the html code?

<html>
<head></head>
<body>
<center><font color=darkred><h1>REGISTRATION FORM</h1></font></center>
<form method=post action="http://localhost:8080/examples/servlet/DataWare">
<font size=4 color=darkblue><b>
first name : <input type=text size=20 name="fn">
<br><br>
last name : <input type=text size=20 name="ln">
<br><br>
Id number : <input type=text size=20 name="id">
<br><br>
User name : <input type=text size=20 name="un">
<br><br>
password : <input type=password size=20 name="passw">
<br><br>
age : <input type=text size=3 name="age">
<br><br>
address : <input type=text size=20 name="add">
<br><br>
type of registration :
<br>
<!------------------------------------------------------------------------------------------------------------------------------->
<input type=radio name="teachorstu" value="teacher">teacher
<br><br> <!-^^^^^^^^^^^^^^->
<input type=radio name="teachorstu" value="student">student
<!--------------here is the problem ^^^^^^^^^^^^^-------------->
<br><br>
</b></font>
<input type=submit value="register">
<br><br>
</form>
</body>
</html>
and the java source code::
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DataWare extends HttpServlet
{
private String firstName;
private String lastName;
private String id;
private String userName;
private String password;
private String age;
private String address;
private String type;
private static Connection connection;
public void init()
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch(Exception e)
{
System.out.println("Registering the Driver was failed");
}
try
{
connection = DriverManager.getConnection
("jdbc:mysql://localhost:3306/ExamDB");
}
catch(Exception exception)
{
System.out.println("Connection with the DataBase failed");
exception.printStackTrace();
System.exit(1);
}
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{
Students student =new Students(connection);
res.setContentType("text/html");
firstName=req.getParameter("fn");
lastName=req.getParameter("ln");
id=req.getParameter("id");
userName=req.getParameter("un");
password=req.getParameter("passw");
age=req.getParameter("age");
address=req.getParameter("add");
/***************************************************************/
type=req.getParameterValues("teachorstu");
/**the problem is here^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^******/
try
{
student.addNewStudent(firstName,lastName,id,userName,password,age,address,type);
}
catch(SQLException sql){}
try
{
if(type=="teacher")
{
PrintWriter out=res.getWriter();
out.println("<html><body width=400 height=400><h1>TEACHER ADMINISTRATION PAGE FOR : "+firstName.toUpperCase()+"</h1>");
out.println("<br><br><input type=submit value='create exam' action=''>");
out.println("<br><br><br><input type=submit value='exam results' action=''>");
out.println("</body></html>");
out.close();
}
else
{
PrintWriter out=res.getWriter();
out.println("<html><body width=400 height=400><h1>STUDENT ADMINISTRATION PAGE FOR : "+firstName.toUpperCase()+"</h1>");
out.println("<br><br><input type=submit value='do exam' action=''>");
out.println("<br><br><br><input type=submit value='exam results' action=''>");
out.println("</body></html>");
out.close();
}
}
catch(Exception e){}
}
}

class Students
{
private Connection connect;
private PreparedStatement addNewStudento;
public Students(Connection c)
{
connect = c;
try
{
addNewStudento = connect.prepareStatement
("INSERT INTO students VALUES (?,?,?,?,?,?,?,?)");
}
catch (SQLException exception)
{
exception.printStackTrace();
}
}
public void addNewStudent(String firstn, String lastn, String idn,
String usern, String passn, String agen, String add, String typen)
throws SQLException
{
addNewStudento.setString(1,firstn);
addNewStudento.setString(2,lastn);
addNewStudento.setString(3,idn);
addNewStudento.setString(4,usern);
addNewStudento.setString(5,passn);
addNewStudento.setString(6,agen);
addNewStudento.setString(7,add);
addNewStudento.setString(8,typen);
if (addNewStudento.executeUpdate()!=1)
{
throw new SQLException("adding new Student failed");
}
}
}
22 years ago

Originally posted by Bosun Bello:
Put it in your doGet or doPost...it depends on your processing needs. String a=request.getParameter("x")

Bosun
thankes bosun
but i know this method and it doesn't help me cause it doesn't get the parameter value it gets the parameter name and on radio buttons you put the same name but different value for each option
and my problem is that i can't get the value


22 years ago
in which method shuld i use at the servlet code for request
the value of a radio button in the html code?
html::
<input type=radio name=x value=z>z
<input type=radio name=x value=y>y
java::
String a=request.someMethod("x");
22 years ago