<!--#包括 file= "Data.inc"--> 1. How to mix JSP with SSI #include? You can include pure HTML in a JSP by using the following methods:
But if the data.inc contains JSP CODE, we can use: <% @include file= "Data.inc"%> 2. How to execute a thread-safe JSP? Just add the following instructions <%@ page isthreadsafe=& quot, fake & quot;%> 3, JSP How to handle the data in HTML form? You can use the built-in request object, as follows: <% Rope clause = Request.getparameter ("item"); int howmany = new Integer (Request.getparameter ("units")). Intvalue (); %> 4, in the JSP how to include a static file? The static contains the following: <%@ include file= "copyright.html"%> The dynamic includes the following: <jsp:include page= "copyright.html" lush= "true" > 5. How to use annotations in JSP? There are four main methods: 1. <%--and--%> <!--and--> 2. // 3. /** and **/ 4.
6. How to perform browsing redirection in JSP? The following methods can be used: Response.sendredirect ("http://ybwen.home.chinaren.com/index.html"); You can also physically change the HTTP header properties as follows: <% Response.setstatus (httpservletresponse.sc_moved_permanently); String newlocn= "/newpath/index.html"; Response.setheader ("Location", NEWLOCN); %> 7, how to prevent the JSP or servlet in the output is not browser saved in the cache? Add the following script to the beginning of the JSP file: <% Response.setheader ("Cache-control", "No-store"); HTTP 1.1 Response.setheader ("Pragma", "No-cache"); HTTP 1.0 Response.setdateheader (& quot; expired & quot;, 0);//block buffer in Proxy Server service %> 8. How to set up cookies in JSP? Cookies are sent as part of the HTTP header, and you can set the following methods: <% Cookie MyCookie = new Cookie (& quot; Aname & quot;,& quot; avalue & quot;); Response.addcookie (MyCookie); %> 9, in the JSP how to delete a cookie? <% Cookie Killmycookie = new Cookie (& quot; MyCookie & quot;, empty); Killmycookie.setmaxage (0); Killmycookie.setpath ("/"); Response.addcookie (Killmycookie); %> 10. How to stop the execution of JSP in the request processing of a JSP The following example: <% if (Request.getparameter ("Wen")! empty =) { Do something Another Return } %> 11. How to define methods in JSP You can define a method, but you cannot directly access the built-in object of the JSP, but rather pass it through the method of the parameter. As follows: <%! Public Rope Howbadfrom (httpservletrequest req) { HttpSession ses = req.getsession (); ...... Restitution of Req.getremotehost (); } %> <% Out.print ("In general, Lao Lee is not a baddie & quot;);" %> <%= Howbadfrom (Request)%> 12, if the browser has been closed cookies, in the JSP how can I open the session to track You can use URL rewriting as follows: hello1.jsp <%@ page session=& quot, real & quot;%> <% Integer num = new integer (100); Session.putvalue ("num", num); Rope URL =response.encodeurl ("hello2.jsp"); %> < a href= ' <%=url%> ' > hello2.jsp </a> hello2.jsp <%@ page session=& quot, real & quot;%> <% Integer i= (integer) session.getvalue ("num"); At the meeting of the OUT.PRINTLN ("num value is" +i.intvalue ()); %> 13, in the JSP can send email? You can use the Sun's private package: SUN.NET.SMTP package. The following script uses the SmtpClient class to send email. <%@ page import= "sun.net.smtp.SmtpClient, java.io.*"%> <% String from= "ybwen@sina.com"; Rope to= "hewenjun@yeah.net, lei@who.com.cn"; Give it a try { SmtpClient customer = new SmtpClient ("mail.xxxxx.xxx"); Client.from (from); Client.to (to); PrintStream message = Client.startmessage (); Message.println ("To: & quot; +"); Send email from JSP message.println ("Subject:!& quot;);" Message.println ("This" is sent from a JSP page!& quot;); Message.println (); Message.println ("cool!:-) & quot;); Message.println (); Message.println ("Good boy & quot;); In genius.com "); Message.println (" I "M Message.println (); Client.closeserver (); } catch (IOException e) { Send email to System.out.println ("ERROR:& quot; +E); } %> Throwable e) request.setattribute ("Javax.servlet.jsp.jspException", e); Getservletconfig (). Getservletcontext (). Getrequestdispatcher (Errorpageurl). Forward (Request,}senderrorredirect (Request,response, "/jsp/myerrorpage.jsp", ex); E.printstacktrace ();}} <%@ page import= "javax.naming.*, Javax.rmi.PortableRemoteObject, Foo. Accounthome, Foo. Account "%> <%! Defines a global reference to an instance of the Sessionbeanhome interface Accounthome Acchome=null;
Public empty jspinit () { Get Home Interface Instance InitialContext cntxt = new InitialContext (); Object ref= cntxt.lookup ("JAVA:COMP/ENV/EJB/ACCOUNTEJB"); Acchome = (accounthome) portableremoteobject.narrow (Ref,accounthome.class); } %> <% Instantiation of Sessionbean Account acct = Acchome.create (); Calling remote methods Acct.dowhatever (...); Mailroom %> 16. When I use a result set, how do I prevent a field that is "null" from being displayed in my HTML input text field? You can define a simple function to achieve your goal, as follows: <%! Rope Blanknull (string s) { Back (empty s = =)? ": s; } %> Then in the form of the JSP, you can use the < input type = "ARTICLE" name = "Shoesize" value= <% =blanknull (shoesize)%> "> Response.setcontenttype ("Application/x-msword"); < jsp:getproperty named =& quot; Wenbean & quot;p roperty=& quot; Someproperty & quot;/> < jsp:setproperty named =& quot; Wenbean & quot;p roperty=& quot; Someproperty & quot;value=& quot; Somevalue & quot;/> 19, using JSP How to obtain the Customer browser information? Use Request.getheader (String) to
20. Can call a JSP like calling a subroutine? Of course you can, with <jsp:include page= "Relativeurl" lush= "true" > 21. After I recompile a class used by my JSP, why does the JVM continue to use my old class? <% @include file= "abc.jsp"%> And <jsp:include page= "abc.jsp" > The difference between? The previous one is statically contained and the latter is dynamically contained
22, the shortcomings of JSP? 1. Debugging a Java program There's no good stuff. 2. Because most servlet engines do not support connection pooling 3. Servlet engine has no standard 4. JSP's interaction with other scripting languages
23, JSP can be recursive call it? Of course, if you submit the form to this page
34, how to achieve the internationalization of JSP? Provide resource bundles property files for various versions
25. How to write text files in JSP? Use the PrintWriter object, such as: <%@ page import= "java.io.*"%> <% Rope str =& quot; print me & quot;; Rope Nameoftextfile = "/usr/anil/imp.txt"; Give it a try { PrintWriter pw = new PrintWriter (new FileOutputStream (Nameoftextfile)); Pw.println (str); Pw.close (); Seize (IOException e) { Out.println (E.getmessage ()); } %> Session.putvalue ("Variable", "value"); <jsp:forward> , the address bar in the browser doesn't change? Using Response.sendredirect ("Newurl")
34, how to convert the JSP 0.9 version of the file to JSP1.1? You can use Sed/awk
35. Use JSP to set the focus of input fields in HTML form without JavaScript? No way
36. What is the best way to connect a buffer pool with a JSP connection to the database? 1. Use JDBC2. 0 driver with this service 2. Use the application server that provides this service 3. Write your own |