JSP question and answer set

zhaozj2021-02-16  104

JSP question and answer set

How to mix using JSP and SSI #InClude? In JSP, you can use the pure html: But if Data.inc contains JSP Code, we can use: <% @ include file = "DATA.INC"%>

How to perform a thread security JSP? Just add the following instructions <% @ page isthreadsafe = "false"%>

How does JSP handle data in HTML FORM? You can use the built-in Request object, as follows: <% string item = request.getParameter ("item"); int howmany = new integer (Request.GetParameter ("Units")). INTVALUE ();%>

How to include a static file? Static contains the following: <% @ include file = "Copyright.html"%> Dynamic contains the following:

How to use notes in JSP? Mainly four methods: 1. <% - with -%> 2. // 3. / ** and ** / 4.

How to perform browse redirection in JSP? Use the following: Response.sendRedirect ("http://ybwen.home.chinaren.com/index.html";); also physically change the HTTP header attribute, as follows: <% response.setstatus (httpservletResponse.sc_moved_persponse.sc_moved_permanently); String newlocn = "/ newpath / index.html"; response.setheader ("location", newlocn);%>

How to prevent the output in the JSP or Servlet does not be saved in Cache by Browser? Add the following scripts 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.setdatehead ("expires", 0); // prevents caching at the proxy server%>

How to set cookie? Cookies in JSP is sent as part of the HTTP header, as follows: <% cookie mycookie = new cookie ("Aname", "Avalue"); response.addcookie (MyCookie);%>

How to delete JSP in a COOKIE <% Cookie killMyCookie = new Cookie ( "mycookie", null); killMyCookie.setMaxAge (0); killMyCookie.setPath ( "/"); response.addCookie (killMyCookie);%>? In a How to stop JSP execution in the request processing of JSP is: <% IF (Request.getParameter ("Wen")! = Null) {// do something} else {return;}%>

How to define methods in JSP You can define methods, but you cannot directly access JSP built-in objects, but pass through parameters. As follows: <%! Public string howbadfrom (httpsession sees = req.getsession (); ... return req.getRemotehost ();}%> <% out.print ("in General, Lao Lee is not bigdie ");%> <% = howbadfrom (request)%>

If Browser has closed cookies, how do I open session in JSP to track the use of URL rewrite, as follows: hello1.jsp <% @ Page session = "true"%> <% integer Num = new integer (100); Session.putValue ("NUM", NUM); String Url = Response.EncodeURL ("Hello2.jsp");%> I can call a JSP error page in servlet? Of course, there is no problem, show how to call within a servlet control logic unit A JSP error page. protected void sendErrorRedirect (HttpServletRequest request, HttpServletResponse response, String errorPageURL, Throwable e) throws ServletException, IOException {request.setAttribute ( "javax.servlet.jsp.jspException", e);.. getServletConfig () getServletContext () getRequestDispatcher (errorPageURL) .forward (request, response);

public void doPost (HttpServletRequest request, HttpServletResponse response) {try {// do something} catch (Exception ex) {try {sendErrorRedirect (request, response, "/ jsp / MyErrorPage.jsp", ex);} catch (Exception e) {E.PrintStackTrace ();}}}

How JSP and Applet communicate how JSP has made good demonstration <% @ page import = "javax.naming. *, Javax.rmi.portableremoteObject, foo.accounthome, foo.account"%> <%! // Define a global reference to the sessionBeanHome interface instance AccountHome Acchome = null; public void jspinit () {// Get Home Interface Instance InitialContext (); Object Ref = CNTXT.LOOKUP ("Java: Comp) / env / ejb / accountntejb "); acchome = (AccountHome) PortableRemoteObject.narrow (ref, accounthome.class);}%> <% // instantiation sessionBean Account ACCT = acchome.create (); // Call remote method ACCT .dowhatever (...); //, etc.%>

When I use a result set, how to prevent fields from "null" display in my HTML input text field? Can define a simple function to achieve the goal, as follows: <%! String blanknull (string s) { RETURN (S == NULL)? "": s;}%>

Then in the JSP's FORM, you can use the

When you use the usebean flag to initialize the bean, you accept the initialization parameters to use the following two tags:


New Post(0)