2013年9月20日星期五

jsp servlet class you can write jsp page when the servlet class ?

I made a second development , I think the nested jsp java code can not do , so I wanted to write in jsp pages servlet class but do not know how to call ,
( Do not tell me to write in java inside , because I did not write jsp pages )
in the web.xml configured via

testServlet
/ jsp / test.jsp

can indeed access to test.jsp but does not call the doGet () doPost method
- The following is a test.jsp
<% @ page language = "java" import = "java.util. *" pageEncoding = "UTF-8"%>
<% @ page import = "com.esoon.cisiss.common.BaseServlet"%>
<% @ page import = "java.io.IOException"%>
<% @ page import = "javax.servlet.ServletException"%>
<% @ page import = "javax.servlet.http.HttpServletRequest"%>
<% @ page import = "javax.servlet.http.HttpServletResponse"%>

<%
String path = request.getContextPath ();
String basePath = request.getScheme () + ":/ /" + request.getServerName () + ":" + request.getServerPort () + path + "/" ;
%>


<%
class testServlet extends BaseServlet {


public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.print ("---------- 1 -------");
System.out.print ("-------- 2 ---------");
}

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost (request, response);
}

}

%>
------ Solution --------------------------------- -----------
can.
------ Solution - -------------------------------------------
a jsp write doPost why , want to do done directly , would like to take the value written directly request.getParameter
------ Solution ------------------------ --------------------
can in fact be used in jsp
<%!
public void method () {
}
%>
to define global methods provide call like, ,

In addition, I tried using the method of the landlord , but it seems not, every time perform the jsp _jspService, set the url-pattern is also true .
I finally found the compiled file :

This servlet is defined within the method , the direct call certainly does not work . .

I would not be specific . .


------ Solution ------------------------------------ --------
agree 5F ah ~ specific reasons I have not tried , I feel so write the configuration file may have a problem it ~
feel no practical value ah ~ in jsp java code to add the already chaotic, but even write servlet execution efficiency will reduce ah ~
------ Solution -------- ------------------------------------
jsp eventually be compiled into a servlet class , jsp bias at the presentation layer , servlet focus logic , and that you might try this jsp compiled into a servlet name Jiaosha the call . you I have not tried this specific ! Great God downstairs seeking to explain it !
------ Solution ---------------------------------------- ----


public final class login_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html;charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
       null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
basePath = basePath +"";


      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("\t<head>\r\n");
      out.write("\t\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n");
      out.write("\t\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n");
      out.write("\t\t<title>欢迎访问");



find a jsp compile java code to look at, call the jsp page is called after
public void _jspService (HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
this method , this method is that you uninstall method body code inside jsp page .
So dopost doget method body written directly in jsp pages can be
------ Solution ------------------- -------------------------
the little brother , you have to first understand what is the relationship servlet and jsp Oh, in fact, simply js is the servlet, the servlet container, such as tomcat, jsp will first resolve . java files , you work under the tomcat directory to find their names next time + "_jsp". java files and . calss file , watching . java files code you can see that you do not need to write doPost and doGet method , and write java code to write directly to the grindstone , but first understand the relevant knowledge ah jsp , such as the nine built-in objects
------ Solution - -------------------------------------------
like you 've never seen .......... Ajax not request a written inside java code jsp page ? write in jsp class . . . Thinking issues now ! ! !
------ Solution ------------------------------------ --------
out.print ( you want to return the contents of the )

remove the contents of the following

------ Solution ------------------------------- -------------
brother ah jsp servlet is okay , you can write any code in the jsp , ah, you can also use javaBean ah , jsp code in the end are the servlet service approach where possible ways how nested inside a class definition
------ Solution ---------------------------- ----------------
LZ novice, even the difference between JSP and Servlet and contact yet clear . Recommend that you search for the next JSP and Servlet difference. Maybe your problem is solved .
------ Solution ---------------------------------------- ----
we still let him clear principle of it , or can only be considered to help him solve the current problems , still do not understand why you did .
------ Solution ---------------------------------------- ----
jsp is a servlet ah
 JSP stands for Java Server Pages, which is a special case servle technology , are the SUN company defines a resource for developing dynamic web technology.
 JSP this technique is characterized by the largest , write jsp like to write html, but :
• It is concerned compared to html , html only provide users with static data , and Jsp technology allows nested java code in the page , to provide users with dynamic data.
• terms compared to servlet , servlet is difficult for data layout , and jsp java code can be used in addition to dynamic data generated at the same time , it is very easy for data layout .
• Jsp Quickstart: jsp page output in the current time.

------ Solution ------------------------------------ --------
Please do not do this , jsp write java code , you can write .
jsp embed servlet can do , you just need to refer to the HttpServlet source, next tomcat source code, which can be found.

But ! ! ! ! jsp write Java will make people feel kind of like feces ah ! ! ! ! Even if you vomit vapid finished ! ! Are you willing to go in the near future it is also one ah ! ! ! There are wood ! ! ! All <% %> ! ! Really want feces ah ! ! ! ! So even think ah ! ! ! ! ! Landlord ! ! ! !
------ Solution - -------------------------------------------
not sure I understand the right is not , LZ just wanted to write an ajax request, but can not write JAVA class , only modify jsp.

$.ajax({
                url : "/brokermark/aaa.jsp",
                type:'post',
                context : this,
                data : {"ddd" : "111"},
                error : function(jqXHR, textStatus, errorThrown) {
                    alert();
                },
                success : function(data, textStatus, jqXHR) {
                    alert(data);
                }
            });

JSP in :

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String ddd = request.getParameter("ddd");
    out.print(ddd+"====");
%>

------ For reference only ----------------------------------- ----


how to write , but you see I write access , and will not perform doPost ()
------ For reference only ------------- --------------------------


You see what I have written I think if servlet through ajax (js inside ) calls this servlet
------ For reference only ----------- ----------------------------
because I am doing is secondary development can only move one step I have this jsp page the need to achieve : the need for treatment twice , point a delete button and then process data to get ID, then : According to the ID of a delete operation returns ( this step requires a delete button step finish point )

------ For reference only ---------------------------------- -----
I need to call me directly using ajax jsp- servlet? The method does not perform inside how do
------ For reference only ------------------------- --------------
jsp is actually a servlet. But it is already implicit in the request, response , etc. 9 large objects.
<%%> you directly in the code block inside the java write business logic code does not need to write anything like what ah methods .
------ For reference only -------------------------------------- -


write directly to your operation in jsp can, and do not need to go write a servlet
For example, you had to define a servlet could this
web.xml

<servlet>
    <servlet-name>testServlet</servlet-name>
     <servlet-class>package.BaseServlet</servlet-class>
</servlet> 


java class

public class testServlet extends BaseServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        //这里会进行你的删除操作
        System.out.print("--------1-------");
        System.out.print("--------2---------");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        this.doPost(request, response);
    }
}

These are the servlet approach, now that you use jsp to complete, first save the configuration web.xml
Suppose jsp files test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.esoon.cisiss.common.BaseServlet" %>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
alert("");
</script>
<%
//这里删除做删除操作
System.out.print("--------1-------");
System.out.print("--------2---------");
%>

------ For reference only ----------------------------------- ----

  
write directly to your operation in jsp can, and do not need to go write a servlet   
For example, you had to define a servlet could this   
web.xml   
  

<servlet>
    <servlet-name>testServlet</servlet-name>
     <servlet-class>package.BaseServlet</servlet-class>
</servlet> 
  
  
java class   
  

public class testServlet extends BaseServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        //这里会进行你的删除操作
        System.out.print("--------1-------");
        System.out.print("--------2---------");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        this.doPost(request, response);
    }
}
  
These are the servlet approach, now that you use jsp to complete, first save the configuration web.xml   
Suppose jsp files test.jsp   
  

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.esoon.cisiss.common.BaseServlet" %>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
alert("");
</script>
<%
//这里删除做删除操作
System.out.print("--------1-------");
System.out.print("--------2---------");
%>
 


I said I could not move the secondary development project java code package only war


------ For reference only ---------------------------------- -----


not need to write doPost and doGet method ? ajax how I call this class how the return value
------ For reference only ----------------------- ----------------

    
write directly to your operation in jsp can, and do not need to go write a servlet     
For example, you had to define a servlet could this     
web.xml     
    

<servlet>
    <servlet-name>testServlet</servlet-name>
     <servlet-class>package.BaseServlet</servlet-class>
</servlet> 
    
    
java class     
    

public class testServlet extends BaseServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        //这里会进行你的删除操作
        System.out.print("--------1-------");
        System.out.print("--------2---------");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        this.doPost(request, response);
    }
}
    
These are the servlet approach, now that you use jsp to complete, first save the configuration web.xml     
Suppose jsp files test.jsp     
    

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.esoon.cisiss.common.BaseServlet" %>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
alert("");
</script>
<%
//这里删除做删除操作
System.out.print("--------1-------");
System.out.print("--------2---------");
%>
         
  
  
I said I could not move the secondary development project java code package only war   
  
 

So you have to look carefully, the java class is said that if you can write java class would write , but you can not , write a good jsp
These are the servlet approach, now that you use jsp to complete, first save the configuration web.xml jsp files
Suppose there are only test.jsp write on the line this jsp , ajax request the jsp path on the line


------ For reference only ---------------------------------- -----

      
write directly to your operation in jsp can, and do not need to go write a servlet       
For example, you had to define a servlet could this       
web.xml       
      

<servlet>
    <servlet-name>testServlet</servlet-name>
     <servlet-class>package.BaseServlet</servlet-class>
</servlet> 
      
      
java class       
      

public class testServlet extends BaseServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        //这里会进行你的删除操作
        System.out.print("--------1-------");
        System.out.print("--------2---------");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        this.doPost(request, response);
    }
}
      
These are the servlet approach, now that you use jsp to complete, first save the configuration web.xml       
Suppose jsp files test.jsp       
      

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.esoon.cisiss.common.BaseServlet" %>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
alert("");
</script>
<%
//这里删除做删除操作
System.out.print("--------1-------");
System.out.print("--------2---------");
%>
               
    
    
I said I could not move the secondary development project java code package only war     
    
         
  
So you have to look carefully, the java class is said that if you can write java class would write , but you can not , write a good jsp   
   These are the servlet approach, now that you use jsp to complete, first save the configuration web.xml jsp files
Suppose there are only test.jsp write on the line this jsp , ajax request the jsp path on the line
  
 

that return values ​​how to write jsp page how to do the java content ID returned back back ?
------ For reference only -------------------------------------- -
zxcvbnm11920 is what I want, and I mean properly understood , but it has been described previously yousteely out, blame my stupid point , did not understand , thank the two men , and also thank you everyone .

没有评论:

发表评论