高手帮个忙:jsp转化为asp.net
哪位大哥帮帮忙,把这段jsp代码转化为asp.net的。数据库为accessenter.jsp(登录页面,用来验正身份的)------------------------...
哪位大哥帮帮忙,把这段jsp代码转化为asp.net的。数据库为access
enter.jsp(登录页面,用来验正身份的)
-----------------------------------------------
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<title>个人成绩查询登录</title>
<body>
<center>
<font color=blue size=4><b><i>
请输入你的学号和密码</b></i>
</font>
<hr>
<form action="result.jsp" method="post">
<table border="1">
<tr><th bgcolor="yellow">学号</th><td>
<input type="text" size=10 name="number"></td></tr>
<tr><th bgcolor="yellow">密码</th><td>
<input type="password" size=10 name="password"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" vaule="查询"></td></tr>
</table>
</form>
<font color="red">
<%
String error=request.getParameter("errortype");
if(error!=null)
{
int errortype;
errortype=Integer.parseInt(error);
switch(errortype)
{
case 1:out.println("请输入学号!");break;
case 2:out.println("请输入密码!");break;
case 3:out.println("搞错,没有此人!");break;
case 4:out.println("密码错误!");break;
default:
}
}
%>
</font>
</body>
</html>
result.jsp(执行查询结果)
--------------------------------------------
<html>
<title>查询结果</title>
<body>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %>
<%
String num=request.getParameter("number");
String password=request.getParameter("password");
int errortype=0;
if(num.equals(""))
{
errortype=1;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else if(password.equals(""))
{
errortype=2;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:odbc:std");
Statement smt=con.createStatement();
String sql="select * from pw where 学号=´"+num+"´";
ResultSet rs=smt.executeQuery(sql);
if(!rs.next())
{
errortype=3;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else if(!rs.getString(2).equals(password))
{
errortype=4;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else
{
sql="select * from score where 学号=´"+num+"´";
rs=smt.executeQuery(sql);
rs.next();
out.println(rs.getString(1)+",你好,你的成绩如下:"+"<hr>");
out.println("<table border=´1´>");
out.println("<tr bgcolor=´gray´><th>姓名</th><th>计算机英语</th><th>软件工程</th><th>C程序设计</th><th>Java程序设计</th><th>数据库原理</th><th>计算机网络</th></tr>");
out.println("<tr><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td></td>"+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+"</td><td>"+rs.getString(6)+"</td><td>"+rs.getString(7)+"</td><td>"+rs.getString(8)+"</td></tr>");
con.close();
}
con.close();
}
%>
</table>
</body>
</html
数据库access,库名:成绩,表名:成绩,字段名准考证号,姓名,成绩。前台输入准考证号和姓名查询成绩,后台添加修改删除成绩。asp.net实现 展开
enter.jsp(登录页面,用来验正身份的)
-----------------------------------------------
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<title>个人成绩查询登录</title>
<body>
<center>
<font color=blue size=4><b><i>
请输入你的学号和密码</b></i>
</font>
<hr>
<form action="result.jsp" method="post">
<table border="1">
<tr><th bgcolor="yellow">学号</th><td>
<input type="text" size=10 name="number"></td></tr>
<tr><th bgcolor="yellow">密码</th><td>
<input type="password" size=10 name="password"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" vaule="查询"></td></tr>
</table>
</form>
<font color="red">
<%
String error=request.getParameter("errortype");
if(error!=null)
{
int errortype;
errortype=Integer.parseInt(error);
switch(errortype)
{
case 1:out.println("请输入学号!");break;
case 2:out.println("请输入密码!");break;
case 3:out.println("搞错,没有此人!");break;
case 4:out.println("密码错误!");break;
default:
}
}
%>
</font>
</body>
</html>
result.jsp(执行查询结果)
--------------------------------------------
<html>
<title>查询结果</title>
<body>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %>
<%
String num=request.getParameter("number");
String password=request.getParameter("password");
int errortype=0;
if(num.equals(""))
{
errortype=1;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else if(password.equals(""))
{
errortype=2;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:odbc:std");
Statement smt=con.createStatement();
String sql="select * from pw where 学号=´"+num+"´";
ResultSet rs=smt.executeQuery(sql);
if(!rs.next())
{
errortype=3;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else if(!rs.getString(2).equals(password))
{
errortype=4;
response.sendRedirect("enter.jsp?errortype="+errortype);
}
else
{
sql="select * from score where 学号=´"+num+"´";
rs=smt.executeQuery(sql);
rs.next();
out.println(rs.getString(1)+",你好,你的成绩如下:"+"<hr>");
out.println("<table border=´1´>");
out.println("<tr bgcolor=´gray´><th>姓名</th><th>计算机英语</th><th>软件工程</th><th>C程序设计</th><th>Java程序设计</th><th>数据库原理</th><th>计算机网络</th></tr>");
out.println("<tr><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td></td>"+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+"</td><td>"+rs.getString(6)+"</td><td>"+rs.getString(7)+"</td><td>"+rs.getString(8)+"</td></tr>");
con.close();
}
con.close();
}
%>
</table>
</body>
</html
数据库access,库名:成绩,表名:成绩,字段名准考证号,姓名,成绩。前台输入准考证号和姓名查询成绩,后台添加修改删除成绩。asp.net实现 展开
2个回答
展开全部
两者的编程思想都不一样。只好重写代码了。
================demo\enter.aspx=================
<%@ Page Title="个人成绩查询登录" Language="C#" AutoEventWireup="true" CodeFile="enter.aspx.cs"
Inherits="DEMO_enter" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" />
<body>
<form id="form1" runat="server">
<asp:MultiView ID="mvMain" ActiveViewIndex="0" runat="server">
<asp:View runat="server">
<table border="1">
<tr>
<th bgcolor="yellow">
学号
</th>
<td>
<asp:TextBox ID="txtNumber" Columns="10" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="txtNumber" ErrorMessage="请输入学号!" ValidationGroup="v1"
Display="None" runat="server" />
</td>
</tr>
<tr>
<th bgcolor="yellow">
密码
</th>
<td>
<asp:TextBox ID="txtPassword" Columns="10" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="txtNumber" ErrorMessage="请输入密码!" ValidationGroup="v1"
Display="None" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnCheck" Text="查询" ValidationGroup="v1" runat="server" />
</td>
</tr>
</table>
<asp:ValidationSummary ValidationGroup="v1" DisplayMode="List" runat="server" />
</asp:View>
<asp:View runat="server">
<p>
<asp:Literal ID="ltrName" runat="server" />,你好,你的成绩如下:</p>
<hr />
<asp:Table ID="tblRst" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell>姓名</asp:TableHeaderCell>
<asp:TableHeaderCell>计算机英语</asp:TableHeaderCell>
<asp:TableHeaderCell>软件工程</asp:TableHeaderCell>
<asp:TableHeaderCell>C程序设计</asp:TableHeaderCell>
<asp:TableHeaderCell>Java程序设计</asp:TableHeaderCell>
<asp:TableHeaderCell>数据库原理</asp:TableHeaderCell>
<asp:TableHeaderCell>计算机网络</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:View>
<asp:View runat="server">
<p style="color:Red;">搞错,没有此人。</p>
<p><a href="javascript:history.back();">返回</a></p>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
===============demo\enter.aspx.cs================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class DEMO_enter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
mvMain.Views[1].Activate += new EventHandler(View1_Activate);
}
protected void View1_Activate(object sender, EventArgs e)
{
Validate("v1");
if (!IsValid)
{
mvMain.ActiveViewIndex = 0;
return;
}
string SQL ="select * from score where 学号='"+txtNumber.Text.Replace("'","''")+"'";
OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~\\App_Data\db1.mdb")); //数据库地址在这里设置
OleDbCommand objCmd = new OleDbCommand(SQL,objConn);
objCmd.Connection.Open();
OleDbDataReader objReader = objCmd.ExecuteReader();
if(objReader.Read())
{
ltrName.Text=objReader[1].ToString();
for(int i=0;i<tblRst.Rows.Count;i++)
tblRst.Rows[1].Cells[i].Text=objReader[i+2].ToString();
}
else
{
mvMain.ActiveViewIndex=2;
}
objReader.Close();
objCmd.Connection.Close();
}
}
================demo\enter.aspx=================
<%@ Page Title="个人成绩查询登录" Language="C#" AutoEventWireup="true" CodeFile="enter.aspx.cs"
Inherits="DEMO_enter" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server" />
<body>
<form id="form1" runat="server">
<asp:MultiView ID="mvMain" ActiveViewIndex="0" runat="server">
<asp:View runat="server">
<table border="1">
<tr>
<th bgcolor="yellow">
学号
</th>
<td>
<asp:TextBox ID="txtNumber" Columns="10" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="txtNumber" ErrorMessage="请输入学号!" ValidationGroup="v1"
Display="None" runat="server" />
</td>
</tr>
<tr>
<th bgcolor="yellow">
密码
</th>
<td>
<asp:TextBox ID="txtPassword" Columns="10" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="txtNumber" ErrorMessage="请输入密码!" ValidationGroup="v1"
Display="None" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnCheck" Text="查询" ValidationGroup="v1" runat="server" />
</td>
</tr>
</table>
<asp:ValidationSummary ValidationGroup="v1" DisplayMode="List" runat="server" />
</asp:View>
<asp:View runat="server">
<p>
<asp:Literal ID="ltrName" runat="server" />,你好,你的成绩如下:</p>
<hr />
<asp:Table ID="tblRst" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell>姓名</asp:TableHeaderCell>
<asp:TableHeaderCell>计算机英语</asp:TableHeaderCell>
<asp:TableHeaderCell>软件工程</asp:TableHeaderCell>
<asp:TableHeaderCell>C程序设计</asp:TableHeaderCell>
<asp:TableHeaderCell>Java程序设计</asp:TableHeaderCell>
<asp:TableHeaderCell>数据库原理</asp:TableHeaderCell>
<asp:TableHeaderCell>计算机网络</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
<asp:TableCell></asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:View>
<asp:View runat="server">
<p style="color:Red;">搞错,没有此人。</p>
<p><a href="javascript:history.back();">返回</a></p>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
===============demo\enter.aspx.cs================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class DEMO_enter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
mvMain.Views[1].Activate += new EventHandler(View1_Activate);
}
protected void View1_Activate(object sender, EventArgs e)
{
Validate("v1");
if (!IsValid)
{
mvMain.ActiveViewIndex = 0;
return;
}
string SQL ="select * from score where 学号='"+txtNumber.Text.Replace("'","''")+"'";
OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~\\App_Data\db1.mdb")); //数据库地址在这里设置
OleDbCommand objCmd = new OleDbCommand(SQL,objConn);
objCmd.Connection.Open();
OleDbDataReader objReader = objCmd.ExecuteReader();
if(objReader.Read())
{
ltrName.Text=objReader[1].ToString();
for(int i=0;i<tblRst.Rows.Count;i++)
tblRst.Rows[1].Cells[i].Text=objReader[i+2].ToString();
}
else
{
mvMain.ActiveViewIndex=2;
}
objReader.Close();
objCmd.Connection.Close();
}
}
展开全部
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="test2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class test2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
页面的东西粘贴过去,把jsp的前台数据访问放到。net的后台访问
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class test2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
页面的东西粘贴过去,把jsp的前台数据访问放到。net的后台访问
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询