java应用程序能定向到一个jsp网页吗?

whyyy78 2002-02-28 10:16:14
我采用如下方法:
try{//作超链接
String urlstr="http://210.42.147.7:8080/telemed/nsosPage.jsp;
url=new URL(urlstr);
AppletContext acty=getAppletContext();
acty.showDocument(url,"_blank");
}catch(MalformedURLException malurlerr){}
可是提示错误:can't resolve symbol "getAppletContext()"
...全文
56 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
waterdragonfly 2002-02-28
  • 打赏
  • 举报
回复
new javax.swing.JEditorPane().setPage(urlString);
whyyy78 2002-02-28
  • 打赏
  • 举报
回复
哦,是java应用程序,不是applet/JApplet.
比如JFrame中的一个菜单响应事件:
public class hisfr extends JFrame{
....
void jMenusos_actionPerformed(ActionEvent e){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@yyy:1521:ORCL";
conn=DriverManager.getConnection(url,"admin","11111");
stmt=conn.createStatement();
rs=stmt.executeQuery("select hjq_ip,hjq_status from hjq_table where hjq_id='"+yhm+"'");
String usip=null,status=null;
while(rs.next())
usip=rs.getString(1);
stmt.close();
if(usip==null){
String ip=InetAddress.getLocalHost().getHostAddress();
try{//Applet里作超链接
String urlstr="http://210.42.147.7:8080/telemed/nsosPage.jsp;
AppletContext acty=getAppletContext();
acty.showDocument(urlstr,"_blank");
}catch(MalformedURLException malurlerr){}
}
}
...
}
wafer_w 2002-02-28
  • 打赏
  • 举报
回复
getAppletContext是由那个对象在调用?
你好象没有写哦!
whyyy78 2002-02-28
  • 打赏
  • 举报
回复
谢谢。
我是想在java应用程序中连接jsp文件,也就是说.java中没有getAppletContext这个函数。怎么办?
hexiaofeng 2002-02-28
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.net.*;
import java.applet.AppletContext;
import javax.swing.*;

public class MyApp extends JApplet
{
public void init(){
JButton b = new JButton("www.yeah.net");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
URL url = new URL("http://www.javasoft.com/index.html");
System.out.println("http://www.javasoft.com/index.html");
getAppletContext().showDocument(url);
}
catch(MalformedURLException murl){
System.out.println("bad url !");
}
}

});
JButton b1 = new JButton("1");
b1.setFocusPainted(true);

JButton b2 = new JButton("2");
// b2.setDefaultCapable(true);
// JRootPane jrp = this.createRootPane();

// jrp.setDefaultButton(b2);
// setRootPane(jrp);

getContentPane().setLayout(new FlowLayout());
getContentPane().add(b);
getContentPane().add(b1);
getContentPane().add(b2);
b1.setSelected(true);
}

}
whyyy78 2002-02-28
  • 打赏
  • 举报
回复
waterdragonfly(水蜻蜓):我用了你的方法出现了如下错误,
java.net.ConnectException:Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
....
这是什么原因,请指教!

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧