本文介绍了嗨,我是玛尼,我是Java新手.我想要一些jsp中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java新手.我想在jsp中为一个gui编写一些代码.在该gui中
4个框和2个按钮.框是行为,toI,查询名称,查询和按钮
继续添加,保存.此gui的主要目的是存储查询
在数据库中.在数据库中有6列.这些列是ID,
随后,执行,toi,查询名称,查询.例如,用户输入一个查询
在查询框中,然后按保存按钮,它将存储在数据库中.
在另一种情况下,用户使用continuetoadd在查询中输入5个查询
按钮,在id列中递增1,随后显示类似1,的值,
该5个查询的2、3、4、5.为此,我想要一些代码.帮助我

hi i am new to java. i want some code for one gui in jsp.In that gui
4 boxes and 2 buttons. boxes are act, toI, queryname,query and buttons
are continuetoadd,save.the main purpose of this gui is store the querys
in database. In database there are 6 columns. those columns are id,
subsequent, act,toi,queryname,query. for eg user enters one query
in query box and press save button, that will store in database.
In another situation user enters 5 querys in query using continuetoadd
button, in id column increment one and subsequent shows values like 1,
2,3,4,5 for that 5 querys. For this i want some code. help me

推荐答案

<%! int val=1; %>
<script type="text/javascript">
function OnSubmitForm()
{
if(document.pressed == "Save")

   {

   document.myform.action ="Save.jsp";  // YOU HAVE TO WRITE A THIRD PAGE TO SAVE THEM UNTO DATABASE

   }
else

   if(document.pressed == "Continue to Add")

   {

   document.myform.action ="ContinuetoAdd.jsp";  // your second page

   }

return true;

}

</script>

<center>
<head> Add New Query </head>

<form name="myform" onsubmit="return OnSubmitForm();">

  <table border="0">
<tr>
  <td> Activity </td>
  <td> <select name="act">
  <option value="" selected>--select--</option>
  <option value="Payment" >Payment</option>
  <option value="Funds" >Funds</option>
  <option value="DMworks">DMworks</option>
  </select></td>
</tr>

<tr>
  <td> Type of Issue  </td>
  <td> <select name="type">
 <option value="" selected>--select--</option>
  <option value="Incident" >Incident</option>
  <option value="FRs" >FRs</option>
  <option value="DMchecks" >DMchecks</option>
  </select> </td>
</tr>

<tr>
  <td>  Query Name  : </td>
  <td><input type="text" name="name"> </td>
</tr>

 <tr>
  <td> Query :</td>
  <td><textarea name="query" rows="10" cols="40">
  </textarea></td>
</tr>
</table><br>


<tr>
   <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Continue to Add" /></td>
   <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Save" /></td>
</tr>

</form>
</center>





//这是第二页continuetoadd.jsp





//this is secondpage continuetoadd.jsp

<%@page import="java.lang.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%! static int val1=1; %>
<%
   String sact=request.getParameter("act");
   String stype=request.getParameter("type");
   String sname=request.getParameter("name");
   String squery=request.getParameter("query");
   String sclick=request.getParameter("click");
 //int nocount=Integer.parseInt(request.getParameter("val"));
%>

<%
    session.setAttribute("activity",sact);
    session.setAttribute("typeofissue",stype);
    session.setAttribute("queryname",sname);
    session.setAttribute("query",squery);
    //session.setAttribute("val",scount);
%>
<%
   String activity=(String)session.getAttribute("activity");
   String typeofissue=(String)session.getAttribute("typeofissue");
   String queryname=(String)session.getAttribute ("queryname");
   String query=(String)session.getAttribute("query");
   //Object value=session.getAttribute("val");
%>

<script type="text/javascript">

function OnSubmitForm()
{
   if(document.pressed == "Save")
   {

   document.myform.action ="Save.jsp";  // YOU HAVE TO WRITE A THIRD PAGE TO SAVE THEM UNTO DATABASE

   }

   else

   if(document.pressed == "Continue to Add")

   {

    <% val1=val1+1; %>
    document.myform.action ="ContinuetoAdd.jsp";  // your second page
    }

   return true;

}

</script>
<html>
<body>
<center>
 <head> ADD NEW QUERY <head>
 <form name="myform" onsubmit="return OnSubmitForm()">

  <table border="0">
<tr>
  <td> Activity </td>
  <td> <select name="act" >
  <option value=<%=activity%> selected><%= activity %></option>

 </select></td>
  </tr>

<tr>
  <td> Type of Issue  </td>
 <td> <select name="type"  >
 <option value=<%=typeofissue%> selected><%=typeofissue%></option>

  </select> </td>
</tr>

<tr>
  <td>  Query Name  : </td>
  <td><input type="text" name="name"> </td>
</tr>

<tr>
  <td> Query :</td>
  <td><textarea name="query" rows="10" cols="40">
  </textarea></td>
</tr>
</table><br>

<tr>
    <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Continue to Add" /></td>
    <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Save" /></td>
</tr>

</form>
</center>
</body>
</html>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:prasad","prasad","prasad");
Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select count(ID) from Data where ID not like ' '");
int count=0,c1=0;
   while(rs.next())
   {
   count=rs.getInt(1);
   }
   count=count+1;

if(val1==1)
{
  c1=1;
  //ResultSetMetaData  md=st.executeUpdate("CREATE SEQUENCE SEQ START WITH 0 INCREMENT BY 1 ");
  PreparedStatement ps=con.prepareStatement("insert into Data values(?,?,?,?,?,?)");
 // ps.executeUpdate("CREATE SEQUENCE SEQ START WITH 0 INCREMENT BY 1");
  ps.setInt(1,count);
  ps.setInt(2,c1);
  ps.setString(3,activity);
  ps.setString(4,typeofissue);
  ps.setString(5,queryname);
  ps.setString(6,query);
  ps.execute();
  ps.close();

}
else
{


    //String sql="insert into Data(\"ID\",\"Subsequent\",\"Activity\",\"Type of Issue\",\"QueryName\",\"Query\") values(' ','"+val+"','"+sact+"','"+stype+"','"+sname+"','"+squery+"')";
   PreparedStatement ps=con.prepareStatement("insert into Data(\"ID\",\"Subsequent\",\"Activity\",\"Type of Issue\",\"QueryName\",\"Query\") values(' ','"+c1+"','"+sact+"','"+stype+"','"+sname+"','"+squery+"')");
   ps.execute();
   ps.close();
 }
session.removeAttribute("activity");
session.removeAttribute("typeofissue");
session.removeAttribute("queryname");
session.removeAttribute("query");

con.close();
%>









//这是我的第三页save.jsp









//this is my thirdpage save.jsp

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%@page import="javax.servlet.*"%>
<%
  String sact=request.getParameter("act");
  String stype=request.getParameter("type");
  String sname=request.getParameter("name");
  String squery=request.getParameter("query");
  String subclick=request.getParameter("click");
  //int nocount=Integer.parseInt(request.getParameter("count"));
  //Long scount=Long.valueOf(request.getParameter("nocount"));
%>
<html>
 <body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:prasad","prasad","prasad");
Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select count(ID) from Data where ID not like ' '");
int count=0,c=0;
///if(==1)
//{
    while(rs.next())
    {
    count=rs.getInt(1);

    }
   count=count+1;
   c=c+1;
   PreparedStatement ps=con.prepareStatement("insert into Data values(?,?,?,?,?,?)");
   ps.setInt(1,count);
   ps.setInt(2,c);
   ps.setString(3,sact);
   ps.setString(4,stype);
   ps.setString(5,sname);
   ps.setString(6,squery);
   ps.executeUpdate();
   ps.close();
/*}
else
{
   c=c+1;
   String sql="insert into Data(\"ID\",\"Subsequent\",\"Activity\",\"Type of Issue\",\"QueryName\",\"Query\") values(' ','"+c+"','"+sact+"','"+stype+"','"+sname+"','"+squery+"')";
   PreparedStatement ps=con.prepareStatement(sql);
   ps.executeUpdate();
   ps.close();
}*/

con.close();
%>
  <head> your details are saved</head>
  </body>
  </html>


//This is my first page
<script type="text/javascript">
function OnSubmitForm()
{
if(document.pressed == "Save")

   {

   document.myform.action ="Save.jsp";  // YOU HAVE TO WRITE A THIRD PAGE TO SAVE THEM UNTO DATABASE

   }
else

   if(document.pressed == "Continue to Add")

   {

   document.myform.action ="ContinuetoAdd.jsp";  // your second page

   }

return true;

}

</script>

<center>
<head> Add New Query </head>

<form name="myform" onsubmit="return OnSubmitForm();">

  <table border="0">
<tr>
  <td> Activity </td>
  <td> <select name="act">
  <option value="" selected>--select--</option>
  <option value="Payment" >Payment</option>
  <option value="Funds" >Funds</option>
  <option value="DMworks">DMworks</option>
  </select></td>
</tr>

<tr>
  <td> Type of Issue  </td>
  <td> <select name="type">
 <option value="" selected>--select--</option>
  <option value="Incident" >Incident</option>
  <option value="FRs" >FRs</option>
  <option value="DMchecks" >DMchecks</option>
  </select> </td>
</tr>

<tr>
  <td>  Query Name  : </td>
  <td><input type="text" name="name"> </td>
</tr>

 <tr>
  <td> Query :</td>
  <td><textarea name="query" rows="10" cols="40">
  </textarea></td>
</tr>
</table><br>


<tr>
   <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Continue to Add" /></td>
   <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Save" /></td>
</tr>

</form>
</center>








//this is mysecond page continuetoadd.jsp


<%@page import="java.lang.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%! static int val1=1; %>
<%
   String sact=request.getParameter("act");
   String stype=request.getParameter("type");
   String sname=request.getParameter("name");
   String squery=request.getParameter("query");
   String sclick=request.getParameter("click");
 //int nocount=Integer.parseInt(request.getParameter("val"));
%>

<%
    session.setAttribute("activity",sact);
    session.setAttribute("typeofissue",stype);
    session.setAttribute("queryname",sname);
    session.setAttribute("query",squery);
    //session.setAttribute("val",scount);
%>
<%
   String activity=(String)session.getAttribute("activity");
   String typeofissue=(String)session.getAttribute("typeofissue");
   String queryname=(String)session.getAttribute ("queryname");
   String query=(String)session.getAttribute("query");
   //Object value=session.getAttribute("val");
%>

<script type="text/javascript">

function OnSubmitForm()
{
   if(document.pressed == "Save")
   {

   document.myform.action ="Save.jsp";  // YOU HAVE TO WRITE A THIRD PAGE TO SAVE THEM UNTO DATABASE

   }

   else

   if(document.pressed == "Continue to Add")

   {

    <% val1=val1+1; %>
    document.myform.action ="ContinuetoAdd.jsp";  // your second page
    }

   return true;

}

</script>
<html>
<body>
<center>
 <head> ADD NEW QUERY <head>
 <form name="myform" onsubmit="return OnSubmitForm()">

  <table border="0">
<tr>
  <td> Activity </td>
  <td> <select name="act" >
  <option value=<%=activity%> selected><%= activity %></option>

 </select></td>
  </tr>

<tr>
  <td> Type of Issue  </td>
 <td> <select name="type"  >
 <option value=<%=typeofissue%> selected><%=typeofissue%></option>

  </select> </td>
</tr>

<tr>
  <td>  Query Name  : </td>
  <td><input type="text" name="name"> </td>
</tr>

<tr>
  <td> Query :</td>
  <td><textarea name="query" rows="10" cols="40">
  </textarea></td>
</tr>
</table><br>

<tr>
    <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Continue to Add" /></td>
    <td><input type="submit" name="click" onclick="document.pressed=this.value" value="Save" /></td>
</tr>

</form>
</center>
</body>
</html>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:prasad","prasad","prasad");
Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select count(ID) from Data where ID not like ' '");
int count=0,c1=0;
   while(rs.next())
   {
   count=rs.getInt(1);
   }
   count=count+1;

if(val1==1)
{
  c1=1;
  //ResultSetMetaData  md=st.executeUpdate("CREATE SEQUENCE SEQ START WITH 0 INCREMENT BY 1 ");
  PreparedStatement ps=con.prepareStatement("insert into Data values(?,?,?,?,?,?)");
 // ps.executeUpdate("CREATE SEQUENCE SEQ START WITH 0 INCREMENT BY 1");
  ps.setInt(1,count);
  ps.setInt(2,c1);
  ps.setString(3,activity);
  ps.setString(4,typeofissue);
  ps.setString(5,queryname);
  ps.setString(6,query);
  ps.execute();
  ps.close();

}
else
{


    //String sql="insert into Data(\"ID\",\"Subsequent\",\"Activity\",\"Type of Issue\",\"QueryName\",\"Query\") values(' ','"+val+"','"+sact+"','"+stype+"','"+sname+"','"+squery+"')";
   PreparedStatement ps=con.prepareStatement("insert into Data(\"ID\",\"Subsequent\",\"Activity\",\"Type of Issue\",\"QueryName\",\"Query\") values(' ','"+c1+"','"+sact+"','"+stype+"','"+sname+"','"+squery+"')");
   ps.execute();
   ps.close();
 }
session.removeAttribute("activity");
session.removeAttribute("typeofissue");
session.removeAttribute("queryname");
session.removeAttribute("query");

con.close();
%>





//this is thirdpage save.jsp


<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%@page import="javax.servlet.*"%>
<%
  String sact=request.getParameter("act");
  String stype=request.getParameter("type");
  String sname=request.getParameter("name");
  String squery=request.getParameter("query");
  String subclick=request.getParameter("click");
  //int nocount=Integer.parseInt(request.getParameter("count"));
  //Long scount=Long.valueOf(request.getParameter("nocount"));
%>
<html>
 <body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:prasad","prasad","prasad");
Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select count(ID) from Data where ID not like ' '");
int count=0,c=0;
///if(==1)
//{
    while(rs.next())
    {
    count=rs.getInt(1);

    }
   count=count+1;
   c=c+1;
   PreparedStatement ps=con.prepareStatement("insert into Data values(?,?,?,?,?,?)");
   ps.setInt(1,count);
   ps.setInt(2,c);
   ps.setString(3,sact);
   ps.setString(4,stype);
   ps.setString(5,sname);
   ps.setString(6,squery);
   ps.executeUpdate();
   ps.close();
/*}
else
{
   c=c+1;
   String sql="insert into Data(\"ID\",\"Subsequent\",\"Activity\",\"Type of Issue\",\"QueryName\",\"Query\") values(' ','"+c+"','"+sact+"','"+stype+"','"+sname+"','"+squery+"')";
   PreparedStatement ps=con.prepareStatement(sql);
   ps.executeUpdate();
   ps.close();
}*/

con.close();
%>
  <head> your details are saved</head>
  </body>
  </html>


这篇关于嗨,我是玛尼,我是Java新手.我想要一些jsp中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 15:03