是否可以从 Java 调用 JSP 页面(我只在 Java 中编写了以下方法,而不是在 jsp 上)?我想做类似的事情..
public void testmethod(){
if(somecondtion){
show some messege to the user.
}
}
如果您的 java 代码在客户端,您可以使用 Url 类访问服务器,如下所示
URL url = new URL("http://www.xyz.com/xyz.jsp");//i.e your Url
URLConnection conn = url.openConnection();
conn.connect();
更好地参考http://docs.oracle.com/javase/1.4.2/docs/api/java/net/URL.html以更好地使用 Url 类方法
您需要 servlet。网络上有很多例子
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
http://courses.coreservlets.com/Course-Materials/csajsp2.html
还有很多
Heard of servlets ? This question is infact a duplicate, which you would have got on searching.