0

Is it possible to call a JSP page from Java (I have written below method in Java only not on jsp) ? I want to do something like..

public void testmethod(){

  if(somecondtion){
    show some messege to the user.
 }  


} 
3
  • We really need some more info here. Are you handling a request and want to programmatically call a JSP? What is the context here? Commented Jun 20, 2012 at 4:33
  • yes I want to call programmatically JSP. I have my method.. public void testmethod(HttpServletRequest request,HttpServletResponse response){ if(somecondtion){ show some messege to the user. } I tried with response.sendredirect("myjsp"); but control not going to jsp Commented Jun 20, 2012 at 4:51
  • possible duplicate of how to call jsp file from java? Commented Jun 20, 2012 at 10:34

3 Answers 3

1

if your java code is in client side you can hit the server using Url class as follows

URL url = new URL("http://www.xyz.com/xyz.jsp");//i.e your Url
URLConnection conn = url.openConnection();
conn.connect();

better refer http://docs.oracle.com/javase/1.4.2/docs/api/java/net/URL.html for better usage of Url class methods

Sign up to request clarification or add additional context in comments.

Comments

0

Heard of servlets ? This question is infact a duplicate, which you would have got on searching.

Comments

0

You need servlets. Lots of example around the web

http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

http://courses.coreservlets.com/Course-Materials/csajsp2.html

and many more

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.