صفحة jsp
<%--
Document : index
Created on : 08/07/2011, 01:11:02 م
Author : سماح
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
function ha()
{
dom = document.getElementById("location").style;
if (dom.visibility == "visible")
{
dom.visibility = "hidden";
}
else {
dom.visibility = "visible";
}
}
</script>
</head>
<body>
<form action ="add" method="post">
<input type="checkbox" name="ch1" id="ch1" value ="متزوج" onclick="ha();"/>متزوج
<br/>
<div id = "location" style = "position: relative; visibility: hidden;">
اسم الزوج <input type="text" name="name" id="name"/>
</div>
<input type="submit" value="add" id="add"/>
<input type="checkbox" name="ch2" id="ch2" value ="ok" />ok
<input type="checkbox" name="ch3" id="ch3" value ="not ok" />not ok
</form>
</body>
</html>وصفحة السيرفليت
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
/**
*
* @author سماح
*/
public class add extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String name=request.getParameter("name");
String status="";
String ch1=request.getParameter("ch1");
String ch2=request.getParameter("ch2");
String ch3=request.getParameter("ch3");
String f="";
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet add</title>");
out.println("</head>");
out.println("<body>");
if(ch1.equals(""))
{
status = "اعزب";
}else{
status ="متزوج";
}
out.println (name+" "+ ch1+" "+ch2+" "+ch3+" " +status+"<br/>");
if(ch2.equals("ok"))
{
f = ch2;
}
out.println (name+" "+ ch1+" "+ch2+" "+ch3);
out.println("</body>");
out.println("</html>");
}
finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}اذا لم اقم بتحديد كلمة "متزوج" فان كافة التعليمات بعده لا تتنفذ
واذا لم اقم بتحديد كلمة "ok" فان ما بعده من تعليمات لا تنفذ
اريد معرفة سبب المشكلة وكيفية حلها ان امكن