servlet代码:
package ne;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.RemoteException;
import java.text.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class servletu extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
TestHome home;
TestDB testdb;
final String testURL = "ne/test.jsp";
final String test2URL = "ne/test2.jsp";
public void init() throws ServletException {
try{
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("TestHome");
home = (TestHome)PortableRemoteObject.narrow(objRef, TestHome.class);
}catch(Exception a){ System.out.println("aaaaaaaaaaa"+a.toString());
} }
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
//PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
Test love1=null;
Iterator i=null;
int j=0; String yztj=request.getParameter("yztj");
String name=request.getParameter("name"); try
{
if (yztj.equals("确认提交")){
String a=(String)request.getParameter("a");
String b=request.getParameter("b");
String c=request.getParameter("c");
String d=request.getParameter("d");
if (d==null){
d="0";
}
float pri=Float.parseFloat(d);
Float aaa=new Float(pri);
love1 = home.create(a,b,c,aaa); }
if (yztj.equals("查询确认")){
int count=countfindname(name);
System.out.println("count=============================="+count);
testdb=new TestDB(count);
i=home.findname(name).iterator() ;
while(i.hasNext()){
Test t=(Test)PortableRemoteObject.narrow(i.next(),Test.class);
testdb.productid[j]=t.getProductid();
testdb.name[j]=t.getName();
testdb.desc[j]=t.getDesc();
testdb.price[j]=t.getPrice();
j++;
} } }
catch (Exception e)
{
System.out.println("2222222222222222222222222222222222222"+e.toString());
}try{ testdb.i=j; session.setAttribute("testdb",testdb);
//mLog.Out("转移" + HomeURL);
if (yztj.equals("确认提交")){
getServletContext().getRequestDispatcher(test2URL).forward(request, response);
return;
}else if(yztj.equals("查询确认")){
getServletContext().getRequestDispatcher(testURL).forward(request, response);
}
return;
}catch(Exception ee){
System.out.println("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"+ee.toString());}
}public int countfindname(String name){
Iterator it=null;
int count=0;
try{
it=home.findname(name).iterator() ;
while(it.hasNext()){
it.next();
count++;
}
}catch(Exception e){
it=null;
System.out.println("Exception!");
}
it=null;
return count;
}}jsp代码:
<%@ page import="Converter,ConverterHome,javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
private Converter converter = null; public void jspInit() {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create();
} catch (RemoteException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (CreateException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (NamingException ex) {
System.out.println("Unable to lookup home: "+ "TheConverter "+ ex.getMessage());
}
} public void jspDestroy() {
converter = null;
}
%>
<html>
<head>
<title>Converter</title>
</head><body bgcolor="white">
<h1><b><center>Converter</center></b></h1>
<hr>
<p>Enter an amount to convert:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form><%
String amount = request.getParameter("amount");
if ( amount != null && amount.length() > 0 ) {
BigDecimal d = new BigDecimal (amount);
%>
<p>
<%= amount %> dollars are <%= converter.dollarToYen(d) %> Yen.
<p>
<%= amount %> Yen are <%= converter.yenToEuro(d) %> Euro.
<%
}
%></body>
</html>
package ne;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.RemoteException;
import java.text.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class servletu extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
TestHome home;
TestDB testdb;
final String testURL = "ne/test.jsp";
final String test2URL = "ne/test2.jsp";
public void init() throws ServletException {
try{
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("TestHome");
home = (TestHome)PortableRemoteObject.narrow(objRef, TestHome.class);
}catch(Exception a){ System.out.println("aaaaaaaaaaa"+a.toString());
} }
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
//PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
Test love1=null;
Iterator i=null;
int j=0; String yztj=request.getParameter("yztj");
String name=request.getParameter("name"); try
{
if (yztj.equals("确认提交")){
String a=(String)request.getParameter("a");
String b=request.getParameter("b");
String c=request.getParameter("c");
String d=request.getParameter("d");
if (d==null){
d="0";
}
float pri=Float.parseFloat(d);
Float aaa=new Float(pri);
love1 = home.create(a,b,c,aaa); }
if (yztj.equals("查询确认")){
int count=countfindname(name);
System.out.println("count=============================="+count);
testdb=new TestDB(count);
i=home.findname(name).iterator() ;
while(i.hasNext()){
Test t=(Test)PortableRemoteObject.narrow(i.next(),Test.class);
testdb.productid[j]=t.getProductid();
testdb.name[j]=t.getName();
testdb.desc[j]=t.getDesc();
testdb.price[j]=t.getPrice();
j++;
} } }
catch (Exception e)
{
System.out.println("2222222222222222222222222222222222222"+e.toString());
}try{ testdb.i=j; session.setAttribute("testdb",testdb);
//mLog.Out("转移" + HomeURL);
if (yztj.equals("确认提交")){
getServletContext().getRequestDispatcher(test2URL).forward(request, response);
return;
}else if(yztj.equals("查询确认")){
getServletContext().getRequestDispatcher(testURL).forward(request, response);
}
return;
}catch(Exception ee){
System.out.println("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"+ee.toString());}
}public int countfindname(String name){
Iterator it=null;
int count=0;
try{
it=home.findname(name).iterator() ;
while(it.hasNext()){
it.next();
count++;
}
}catch(Exception e){
it=null;
System.out.println("Exception!");
}
it=null;
return count;
}}jsp代码:
<%@ page import="Converter,ConverterHome,javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
private Converter converter = null; public void jspInit() {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create();
} catch (RemoteException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (CreateException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (NamingException ex) {
System.out.println("Unable to lookup home: "+ "TheConverter "+ ex.getMessage());
}
} public void jspDestroy() {
converter = null;
}
%>
<html>
<head>
<title>Converter</title>
</head><body bgcolor="white">
<h1><b><center>Converter</center></b></h1>
<hr>
<p>Enter an amount to convert:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form><%
String amount = request.getParameter("amount");
if ( amount != null && amount.length() > 0 ) {
BigDecimal d = new BigDecimal (amount);
%>
<p>
<%= amount %> dollars are <%= converter.dollarToYen(d) %> Yen.
<p>
<%= amount %> Yen are <%= converter.yenToEuro(d) %> Euro.
<%
}
%></body>
</html>
解决方案 »
- struts2文件上传 求解决
- session 问题
- 求助:控制台报错
- 当数据库表新增了一个字段时 hibernate怎么更新?
- 来人接分啊 !!! java.rmi.NotBoundExcetion 发生条件问题
- 各位仁兄,请问如何将网页中的html代码导出为word文档格式[java实现]
- 128M内存可否装weblogic?
- 在elipse3.0中如何在线安装jbossIDE?。。兄弟在线等。。。
- 推荐几本书!
- web应用中 获取spring的bean
- 对JAVA版的兄弟大声喊 “ 求EJB开发捷径 ~~~~~~~~~~~~!”
- resin 的 web.xml 中 数据库配置问题!!!急
(我甚至连JAR文件做什么都不知)
难道是将EJB工程中的JAR文件拷贝到相应Servlet的目录中吗?