΢ Ͷ ^ ھ

cba新赛程 :jsp Fĺmvcģʽʾ

cba㶫 www.axwwg.com  •rg2020-01-15 15:59:31   ߣ   ҪuՓ(0)

Čvjsp Fĺmvcģʽoҹ҅w£
jsp : java servlet page
MVCȫModel View Controllerģ(model)ҕD(view)

Čvjsp Fĺmvcģʽoҹ҅w£

jsp : java servlet page

MVCȫModel View Controllerģ(model)ҕD(view)(controller)ĿsһNܛOӋ䷶һNI߉݋@ʾxķMaI߉݋ۼһڸM͂Իƽ漰ÑͬrҪ¾I߉݋MVCصİlչӳyݔ̎ݔһ߉݋ĈDλÑĽY

ʾdemo

ӳ̎

/WEB-INF/web.xml

<?xml version="1.0" encoding="utf-8" ?>
<web-app xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xmlns="//java.sun.com/xml/ns/javaee" xmlns:web="//java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="//java.sun.com/xml/ns/javaee //java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>Test</display-name>
  <servlet>
    <servlet-name>indexServlet</servlet-name>
    <servlet-class>
      web.app.controller.IndexController
    </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>indexServlet</servlet-name>
    <url-pattern>/index.do</url-pattern>
  </servlet-mapping>
</web-app>

servletث@g[Ոservlet-mapping url-pattern ҎtՈ󽻽oservlet-mappingservlet-name servletȥ̎

OúúLg[LԓĿµindex.doӳoweb.app.controller.IndexController ̎

IndexController.java

package web.app.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/IndexController")
public class IndexController extends HttpServlet
{
  /**
   * 
   */
  private static final long serialVersionUID = -8227194254553105913L;
  @Override
  public void doGet(HttpServletRequest request,HttpServletResponse response)
       throws ServletException, IOException 
  {
    try{
      response.setCharacterEncoding("utf-8");
      response.setContentType("text/html;charset=utf-8");
      //response.getWriter().println("success");
      request.setAttribute("test","hello world this is class name index controller");
      request.getRequestDispatcher("view/index.jsp").forward(request, response);;
    }catch(Exception e)
    {
      System.out.println("error");
      e.printStackTrace();
    }
  }
}

עጣ@Override wжxԓ

еservletҪ^HttpServlet̎requestՈ

IndexController ̎ɺɵĔ惦requestȻԓrequestضview/index.jsp

doGet fǽgetՈ request response Ոrequest 푑 response

view/index.jsp

<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>index</title>
  </head>
  <body>
    <p><%=request.getAttribute("test") %></p>
  </body>
</html>

requestЫ@ú˔

FĺMVCģʽ

ϣjspOӋ

ܸdȤ:

  • JSPʹMVCģʽɄh޸Ĺ܌Ԕ
  • JSPʹServletFMVCģʽԔ
  • springMVCΌcontrollerДfjsp
  • springMVCΌcontrollerModelfjsp
  • SpringMVC jspfxȡֵ
  • \ՄSpringMVC jspǰ_@ȡķʽ EL_ʽ
  • JSP_lspring mvcĿЌF~̖Ξg[
  • JSPspringmvcvalidatorע
  • JavaWebFÑעԹ܌a(Servlet+JSP+JavaBeanģʽ)

P

  • jsp Fĺmvcģʽʾ

    jsp Fĺmvcģʽʾ

    Čvjsp Fĺmvcģʽoҹ҅w£ jsp : java servlet page MVCȫModel View Controllerģ(model)ҕD(view)
    2020-01-15
  • Qtʾʽƥ($regex)һmongocpuռʸߵĆ}

    Qtʾʽƥ($regex)һmongocpuռʸߵĆ}

    ijһOصmongocpuʹʸ˺ܶһlF@NZģ db.example_collection.find({ "idField" : { "$regex" : "1234567890123
    2020-01-15
  • վ֙} P]

    վ֙} P]

    202019֪վLߐվWFˡWվSoՈԺLʼܶWѶԞǐվWRrϵyµֹ죨2020112գ߀]л֏ĿǰվWٷ
    2020-01-13
  • es6 forѭhletvar^eԔ

    es6 forѭhletvar^eԔ

    letvar^e for(var i=0;i<5;i++){ setTimeout(()=>{ console.log(i);//55 },100) } console.log(i);//5 console.log('=============') for(let
    2020-01-12
  • pythonJMeteryԇTornadoĶྀ

    pythonJMeteryԇTornadoĶྀ

    JMeterĺ &#8195;&#8195;JMeterApacheM_lĻJavaĉyԇڌܛyԇOӋWebÜyԇUչyԇI
    2020-01-12
  • Java ַz㷨aFԔ

    Java ַz㷨aFԔ

    һַz㷨B ַzbinary searchַQ۰zַzĻ˼OֵеԪ؏СشڔMarrayõ
    2020-01-12
  • LinuxPHP+Apache26֪İȫO

    LinuxPHP+Apache26֪İȫO

    PHPһN_Դ_Zú܏VApache webṩ@Nͨ^HTTPHTTPSfhLļ̓òķ_ZԕN
    2020-01-12
  • tensorflowӋDY

    tensorflowӋDY

    ӋD TensorFlow ӋDʾӋ΄ ӋDһNDÁxӋĽYHϾһϵеĺĽM ÈDķʽÑͨ^һЩ
    2020-01-12
  • Python3.x+Ѹx Ԅd߷ӰČF

    Python3.x+Ѹx Ԅd߷ӰČF

    Ҫ^ҶæЩʲôһ׹˾NƱ؛@^ĚһwƼ߀˼ϰడwƼ=a=һдaʮe=o
    2020-01-12
  • ΢СȾHTML3NQc}Q

    ΢СȾHTML3NQc}Q

    󲿷WebõĸıݶHTMLַʽ惦ͨ^HTMLęnȥչʾHTMLȻ]І}΢СĺQ顸С򡹣
    2020-01-12