我有8x8的表我想在jsp中随机显示图像或值

时间:2013-10-12 05:15:57

标签: java html sql oracle jsp

我想显示图像的网格视图  但我希望每次我打开视图图像采取随机值我的意思是不同的imgs

public class database extends HttpServlet 

{

private static final long serialVersionUID = 1L;

String firstname;
String lname;
String Email;
String ContactNo;
String Address;
String town;
String pincode;
String pancard ;
String voterId;
String f1,f2,f3,f4,s1,s2,s3,s4;

/**
 * @see HttpServlet#HttpServlet()
 */
public database() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    Statement st = null;
    PrintWriter pwinsert = response.getWriter();
     firstname=request.getParameter("fname");
     lname=request.getParameter("lname");
     Email=request.getParameter("email");
     ContactNo=request.getParameter("contactNo");
     Address=request.getParameter("address");
     town=request.getParameter("fname1");
     pincode=request.getParameter("fname2");
     pancard=request.getParameter("fname3");
     voterId=request.getParameter("fname4");
     f1=request.getParameter("firstimgval1");
     f2=request.getParameter("secimgval1");
     f3=request.getParameter("thirdimgval1");
     f4=request.getParameter("forthimgval1");
     s1=request.getParameter("firstimgval2");
     s2=request.getParameter("secimgval2");
     s3=request.getParameter("thirdimgval2");
     s4=request.getParameter("forthimgval2");
      try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
          System.out.println("driver  loaded");
      }
      catch(ClassNotFoundException ex)    {
          System.out.println("driver not loaded");

      }


      String URL = "jdbc:oracle:thin:@localhost:1521:xe";
      String Username = "system";
      String Password = "toushif";
    try
    {


         con = DriverManager.getConnection(URL,Username,Password);
         ps = con.prepareStatement("INSERT INTO TOU1 (MOBILE,LNAME,FNAME,EMAIL,ADDRESS) VALUES (?,?,?,?,? )");
         ps.setString(1,ContactNo); 
         ps.setString(2,lname);
         ps.setString(3,firstname);
         ps.setString(4,Email);
         ps.setString(5,Address);


         int i = ps.executeUpdate();
         pwinsert.println(i);

         if(i!=0)  
         {
             pwinsert.println("data has been stored");





         }
         else    {
             pwinsert.println("data could not be stored");
         }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    // TODO Auto-generated method stub
}

1 个答案:

答案 0 :(得分:0)

步骤

  1. 假设您从数据库中获取了list
  2. 将此list设置为http-request attribute
  3. 并从RequestDispatcher获取httpRequest
  4. 然后在JSP中使用

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <Table>
    <Tr>
         <td>col1</td> 
         <td>col2</td>
    </tr>
    <c:forEach var="i" items="${listName}">
      <tr>
          <td>
            <c:out value="${i['col1']}"/>
          </td>          
          <td>
            <c:out value="${i['col1']}"/>
          </td>
      <tr>
    </c:forEach>
    </table>