2013年9月23日星期一

How do access a JSP page to let others get the return value , there is someone else how to access the functions to write code ?

As stated , for example, I want to be a JSP page , which the function is to look at the database access , check out a value , others visit my page and get the return value.
Besides the detailed points , for example, I have a JSP page (www.g3mms.cn/a.jsp), a.jsp function is to read the code in the database , execute a query like SELECT * FROM student, draw a rs.getString (1) the value , and then let others access a.jsp, and get this value.
I want to have two aspects, one is the content of this page a.jsp how to write code ? ? Two other people and get access to my a.jsp how to realize the value of the function , as others do a b.jsp page, and then visit my a.jsp page and get the value of the contents of this b.jsp how to write code ? ?

please say some of the details , the best on the entire code , not only part of the ah , thank you

------ Solution ------------------------------------ --------
a.jsp interface :


<%
A gd = new A ();
String res_ = gd.getInfo () ;/ / Here is a java class method to query the database is the database identified values ​​res_
response.setContentType ("text / xml");
response.setCharacterEncoding ("utf-8");
response.getWriter (). println (res_);
response.flushBuffer ();
response.getWriter (). close ();
out.clear ();
out = pageContext.pushBody ();
%>
------ For reference only ------------------------------- --------


this I'm going to ask com.client.service.FeeManager download a bag? ?
There b.jsp code you will give it, thank you
------ For reference only -------------------- -------------------

is the introduction of class A, I glued directly to the code over, forgot to change it. . .
------ For reference only -------------------------------------- -


Oh , Oh, good , thank you, or ask you not give a b.jsp code?
------ For reference only -------------------------------------- -
b.jsp or write java class :

String result = "";
String urlName = "www.g3mms.cn/a.jsp";
URL U = new URL (urlName);
URLConnection connection = U.openConnection ();
connection.connect ();
BufferedReader in = new BufferedReader (new InputStreamReader (connection
. getInputStream ()));
String line;
while ((line = in.readLine ())! = null) {
result = result + line;
}
in.close ();

result is to get the return value a.jsp

------ For reference only ---------------------------------- -----
in fact, you should write a pure Servlet to finish this thing. As an API exists.

If there JSP necessary, visit his good.
------ For reference only -------------------------------------- -


Will use references b.jsp What kind do ? There line is what is the use ?
------ For reference only -------------------------------------- -

Oh , I even will not only use the JSP , Servlet will not write the way , you can provide a right, thank
------ For reference only - -------------------------------------
String result = "" ; ;
String urlName = "www.g3mms.cn/a.jsp";
URL U = new URL (urlName);
URLConnection connection = U.openConnection ();
connection.connect ();
BufferedReader in = new BufferedReader (new InputStreamReader (connection
. getInputStream ()));
String line;
while ((line = in.readLine ())! = null) {
result = result + line;
}
in.close ();

This paragraph written in the main method where the reslut printed on it. . .
------ For reference only -------------------------------------- -

Will this also can be directly written in JSP pages , right ? Written JSP page to change somewhere?
------ For reference only -------------------------------------- -
not change

  
Will this also can be directly written in JSP pages , right ? Written JSP page to change somewhere?  
------ For reference only ---------------------------------- -----

Will this also can be directly written in JSP pages , right ? Written JSP page to change somewhere?         

Okay, thank you , I'll go try it , and then there is this code is to quote what kind of right ? ? ?
------ For reference only -------------------------------------- -
brothers run the main method where you try not to know , and , no other party jar package
------ For reference only --------- ------------------------------

Dude, sorry ah , I tune the next, no understand the whole , I am poor standard, sorry, this is my code b.jsp
<% @ page import = "java.sql. *"%>
<% @ page import = "java.net. *"%>
<% @ page import = "java.io. *"%>
<%
String result = "";
String urlName = "a.jsp";
URL U = new URL (urlName);
URLConnection connection = U.openConnection ();
connection.connect ();
BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream ()));
String line;
while ((line = in.readLine ())! = null) {
result = result + line;
}
in.close ();
out.print (result);
%>

may prompt

org.apache.jasper.JasperException: An exception occurred processing JSP page / b.jsp at line 7

4: <%
5: String result = "";
6: String urlName = "a.jsp";
7: URL U = new URL (urlName);
8: URLConnection connection = U.openConnection ();
9: connection.connect ();
10: BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream ()));

------ For reference only ---------------------------------- -----
you first run through the main method , and then paste the code directly in the <% %> middle on it,
6: String urlName = "a.jsp";

I sent you this sentence with the apparent inconsistency . .
------ For reference only -------------------------------------- -

Dude, sorry ah , I tune the next, did not understand the whole , I am poor standard, sorry, this is my code b.jsp   
<% @ page import = "java.sql. *"%>   
<% @ page import = "java.net. *"%>   
<% @ page import = "java.io. *"%>   
<%   
String result = "";   
String urlName = "a.jsp";   
URL U = new URL (urlName);   
URLConnection connection = U.openConnection ();   
connection.connect ();   
BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream ()));   
String line;   
while ((line = in.readLine ())! = null) {   
result = result + line;   
}   
in.close ();   
out.print (result);   
%>   
  
may prompt   
  
org.apache.jasper.JasperException: An exception occurred processing JSP page / b.jsp at line 7   
  
4: <%   
5: String result = "";   
6: String urlName = "a.jsp";   
7: URL U = new URL (urlName);   
8: URLConnection connection = U.openConnection ();   
9: connection.connect ();   
10: BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream ()));   
 
Perhaps you refer a.jsp directory for storing error , consider storing to disk , with the absolute path to access a.jsp.
------ For reference only -------------------------------------- -


Well, I used the absolute path , and like to use , thanks
brother , there are two questions , would like to ask , first, in the a.jsp can display the results , count to run properly, but also shows

XML page can not be displayed .
not view XML input using style sheet . Please correct the error and then click the Refresh button, or try again later.


---------------------------------------------- ----------------------------------

top of the document is invalid. Processing resource 'http://127.0.0.1:8080/CallCenter2/a.jsp' error. Line 1 , position : 1

0
how does this solve the next , um, the XML about it , if this explanation is not good , then I do not have an XML also, anyway b.jsp received normal value , but would like to learn next , huh

two is, if a.jsp shows the values ​​of two or more words , to b.jsp can also be fully received , but unified assigned to the variable result , and ask how to put more in b.jsp of values ​​to distinguish ah, this is the key, as easy to talk about in detail please , thank
------ For reference only ---------------- -----------------------

Dude, sorry ah , I tune the next, did not understand the whole , I am poor standard, sorry, this is my code b.jsp     
<% @ page import = "java.sql. *"%>     
<% @ page import = "java.net. *"%>     
<% @ page import = "java.io. *"%>     
<%     
String result = "";     
String urlName = "a.jsp";     
URL U = new URL (urlName);     
URLConnection connection = U.openConnection ();     
connection.connect ();     
BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream ()));     
String line;     
while ((line = in.readLine ())! = null) {     
result = result + line;     
}     
in.close ();     
out.print (result);     
%>     
    
may prompt     
    
org.apache.jasper.JasperException: An exception occurred processing JSP page / b.jsp at line 7     
    
4: <%     
5: String result = "";     
6: String urlName = "a.jsp";     
7: URL U = new URL (urlName);     
8: URLConnection connection = U.openConnection ();     
9: connection.connect ();     
10: BufferedReader in = new BufferedReader (new InputStreamReader (connection.getInputStream ()));     
         
Perhaps you refer a.jsp directory for storing error , consider storing to disk , with the absolute path to access a.jsp.  
handy with an absolute path , thank you attention
------ For reference only ------------------------ ---------------

  
Well, I used the absolute path , and like to use , thanks   
brother , there are two questions , would like to ask , first, in the a.jsp can display the results , count to run properly, but also shows   
  
XML page can not be displayed .   
not view XML input using style sheet . Please correct the error and then click the Refresh button, or try again later.   
  
  
---------------------------------------------- ----------------------------------   
  
top of the document is invalid. Processing resource 'http://127.0.0.1:8080/CallCenter2/a.jsp' error. Line 1 , position : 1   
  
0   
how does this solve the next , um, the XML about it , if this explanation is not good , then I do not have an XML also, anyway b.jsp received normal value , but would like to learn next , huh   
  
two is, if a.jsp shows the values ​​of two or more words , to b.jsp can also be fully received , but unified assigned to the variable result , and ask how to put more in b.jsp of values ​​to distinguish ah, this is the key, as easy to talk about in detail please , thank you  


a : a.jsp which you act as this function in the role of the controller , do the business logic processing , did not play in view of the role , in your a.jsp simply had not been used to show the code , which is why there will be a direct request a.jsp white tips.

two : There are many ways , a.jsp the result is essentially a string , since the string , there are many ways to store multiple values ​​, xml, json, or the most primitive with a | or , or a lot of variety you like delimiter to split , b.jsp get this string after the split can be according to the rules .
------ For reference only -------------------------------------- -

    
Well, I used the absolute path , and like to use , thanks     
brother , there are two questions , would like to ask , first, in the a.jsp can display the results , count to run properly, but also shows     
    
XML page can not be displayed .     
not view XML input using style sheet . Please correct the error and then click the Refresh button, or try again later.     
    
    
---------------------------------------------- ----------------------------------     
    
top of the document is invalid. Processing resource 'http://127.0.0.1:8080/CallCenter2/a.jsp' error. Line 1 , position : 1     
    
0     
how does this solve the next , um, the XML about it , if this explanation is not good , then I do not have an XML also, anyway b.jsp received normal value , but would like to learn next , huh     
    
two is, if a.jsp shows the values ​​of two or more words , to b.jsp can also be fully received , but unified assigned to the variable result , and ask how to put more in b.jsp of values ​​to distinguish ah, this is the key, as easy to talk about in detail please , thank you          
  
  
a : a.jsp which you act as this function in the role of the controller , do the business logic processing , did not play in view of the role , in your a.jsp simply had not been used to show the code , which is why there will be a direct request a.jsp white tips.   
  
two : There are many ways , a.jsp the result is essentially a string , since the string , there are many ways to store multiple values ​​, xml, json, or the most primitive with a | or , or a lot of variety you like delimiter to split , b.jsp get this string after the split can be according to the rules .  
Thank you, knot posted

没有评论:

发表评论