zoukankan      html  css  js  c++  java
  • 服务器建设问题

    1.JavaEE 无法查看自己工程下login.html 文件

    解决方法: login.html 文件必须建在 WebContent目录下,不应该建立在WEB-INF下,这样导致 当 login.html 文件使用 run server时无法加载

    WEB-INF/lib 只存放 web.xml 文件,其他.jsp.html放在 WebContent目录下

    2. Java Web工程中 设置默认的启动页面通过web.xml 文件进行配置

      在 WebContent/WEB-INF/web.xml  用来配置与Servlet与项目相关的信息

    3. Get Vs  Post 请求:

    1.浏览器地址栏中输入某个URL地址或者点击网页超链接,此时HTTP消息请求方式是Get

     2. 网页中<from>表单元素method="GET'

    3.传输数据量1KB之下,

    4.如何从HTMLPost数据进行真确的接受

    <from action="demo" method="get">

    HTML中from 中 action属性将表单提交到名为 demo的页面上

    对于 web.xml 配置: <url-pattern>/login<url-pattern>  <url-parrten> 配置名称必须要与 .jsp 中From标签中action属性保持 一致(不能用/)

    其中代码:如下:在loginServlet.java过程中就可以写出其中东西

    最好在浏览器上进行输入,不知道为什么在javaEE自己上输入没有反应

     

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     3 xmlns="http://java.sun.com/xml/ns/javaee" 
     4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     5 id="WebApp_ID" version="3.0">
     6 
     7             <servlet>
     8                         <!-- 信息配置 -->
     9             <!-- 将 LoginServlet.java 命名成LoginServlet 
    10             (当然命名成其他,保证mapping中名称一样) -->
    11               <servlet-name>login</servlet-name> 
    12               <servlet-class>com.tets.LoginServlet</servlet-class>     
    13               <load-on-startup>-1</load-on-startup>
    14             </servlet>
    15       
    16   
    17         <servlet-mapping>
    18               <servlet-name>login</servlet-name>
    19               <!-- 下面写上html action属性提交的是哪个页面 -->
    20               <url-pattern>/login1</url-pattern>
    21               
    22         </servlet-mapping>
    23     
    24      
    25  
    26 </web-app>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
                <!-- 表单提交 移交方式get 提交到 LoginServlet -->
                <form action="login1" method="post">
                    user:<input type="text" name="user"/><br>
                    password:<input type="password" name="password"/><br>
               
                    <input type="submit" value="submit"/>
                    <input type="reset" value="reset"/>
                
                </form>
    </body>
    </html>

    对于 LoginServlet.java:

     1 package com.tets;
     2 
     3 import java.io.IOException;
     4 
     5 import javax.servlet.Servlet;
     6 import javax.servlet.ServletConfig;
     7 import javax.servlet.ServletException;
     8 import javax.servlet.ServletRequest;
     9 import javax.servlet.ServletResponse;
    10 
    11 /**如何提取方法中获取请求信息*/
    12 public class LoginServlet  implements Servlet{
    13 
    14     @Override
    15     public void destroy() {
    16         // TODO Auto-generated method stub
    17         
    18     }
    19 
    20     @Override
    21     public ServletConfig getServletConfig() {
    22         // TODO Auto-generated method stub
    23         System.out.println("config 方法");
    24         return null;
    25     }
    26 
    27     @Override
    28     public String getServletInfo() {
    29         // TODO Auto-generated method stub
    30         System.out.println("getServletInfo 方法");
    31         return null;
    32     }
    33 
    34     @Override
    35     public void init(ServletConfig arg0) throws ServletException {
    36         // TODO Auto-generated method stub
    37         //System.out.println("Init 方法");
    38     }
    39 
    40     @Override
    41     public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    42         // TODO Auto-generated method stub
    43         System.out.println("html 请求来了");
    44         
    45         System.out.print(request);
    46         String user=request.getParameter("user");
    47         String password=request.getParameter("password");
    48         
    49         System.out.println(user+", "+password);
    50     }
    51 
    52 }
    View Code

     5.HttpServletRequest:是属于Servlet的子接口,其中有大量Http方法
    URI:去掉本站点之后信息,相当于对站点中信息的定位

    URL:站点+URI  

    HttpQueryString()方法可以得到get方法提交的数据

    6. GenericServlet:

        1.Servlet 和 ServletConfig接口的实现,但是抽象类,其中service方法是抽象方法

      2.GenericServlet 中声明一个ServConfigl类型的成员变量,在init(ServletConfig) 直接对其初始化

      3.自己重载init()无参方法保留原先init(ServletConfig)有参方法,这个无参方法用于给子类进行覆盖重写,不见了重写init的有参方法

    7.重定向 Vs 转发

     重定向:服务器收到用户的请求之后,经过其处理修改用户的请求URL信息,在返回给用户,这样用户在一次使用这个请求时候被动的使用新请求,其不会跳转到原来的URL上

    目的:防止用户提交完数据之后 点击浏览器刷新再一次提交数据;

    转发:服务器接受到数据 不进行修改在转发给其他的组件最后在回送用户

    8.Seesion会话作用:

    Seesion主要是对会话的跟踪,http协议是无状态的协议,客户每一次读取web页面时候,服务器都会打开一个新的会话;

    Https 是SSL+Http的加密性质传输(不同于HTTP 与TCp/IP的加密身份认证),两者传输方法和接口不一样http:80,https:443  --有一个CA认证系统

    9. @WebServlet()标注配置问题

        1).在多个请求去往同一个Servlet 时候,同时利用反射机制 创建方法,当XXX.do 的URL请求去往同一个Servlet,使用@WebServlet进行标注配置 使用

    getServletPath() ,提取出想实现的方法

    结果显示 左侧浏览器:

     10.如果如下出现了java.lang.ClassNotFoundException: org.apache.commons.dbutils.ResultSetHandler

      解决的方案 是Tomcat的lib下没有相对应的的,jar 文件,因此将dbUtils.jar包放到lib下面

    11. 标签问题,有时候出现的是版本问题 :

     <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%> 不用 <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>

    12.超链接的方式 get请求的方式

  • 相关阅读:
    2016年中国大学生程序设计竞赛(杭州)解题报告
    HNOI2017滚粗记
    BZOJ4515 SDOI2016 游戏
    BZOJ2157 旅行 模拟
    codevs2019 Uva10029 递变阶梯
    POJ 2585 Window Pains 题解
    linux 下 打包 和解压缩
    php 分页
    js 四舍五入
    angularjs 过滤多组数据
  • 原文地址:https://www.cnblogs.com/woainifanfan/p/6648665.html
Copyright © 2011-2022 走看看