RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-219792

ZOOM SMASH's questions

Martin Hope
ZOOM SMASH
Asked: 2022-07-15 03:42:24 +0000 UTC

异步方法启动

  • 1

有一个Tcp客户端类,我的想法很简单:连接服务器,异步启动监听服务器消息的方法。当我运行 ReadStream 方法时,我特别不指定 await 以免等待它完成,但是,仍然没有发生异步。

 class Client : IDisposable
{
    ...

    public async Task ConnectAsync(string host, int port)
    {
        await tcpClient.ConnectAsync(IPAddress.Parse(host), port);
        if (tcpClient.Connected)
        {
            System.Console.WriteLine("Connected!");
            var task = ReadStream(token);
            activeTasks.Add(task);
            System.Console.WriteLine("Task runned");
        }
        else
        {
            System.Console.WriteLine("Failed to connect :(");
        }

    }

    ...

    private async Task<string> ReadStringFromStreamAsync(NetworkStream stream, int size)
    {
        var buffer = new byte[size];
        int length = await stream.ReadAsync(buffer, 0, buffer.Length);
        return Encoding.UTF8.GetString(buffer, 0, length);
    }

    private async Task ReadStream(CancellationToken token)
    {
        var stream = tcpClient.GetStream();
        while (!token.IsCancellationRequested)
        {
            if (stream.DataAvailable)
            {
                string message = await ReadStringFromStreamAsync(stream, 1024);
                System.Console.WriteLine("Recieved message: " + message);
            }
        }
    }
}

如果我通过 运行该方法Task.Run(()=>ReadStream(token)),那么一切都会按我的需要进行。这对我来说有点奇怪,因为我的方法也会返回Task,并且根据我的逻辑(很可能是不正确的),当遇到意外时,Task该方法应该异步运行。在所有的培训时间里,我已经对这个话题进行了 3 次深入研究,但仍然对这种机制的功能的想法非常薄弱。因此,如果在解决此问题的示例中某些部分能达到我的要求,那就太好了。因此,我有两个问题:

  1. 为什么ReadStream尽管存在该方法但没有异步启动该方法await(通常没有说明由于它不存在该方法是同步执行的)?

  2. 如果通过 异步运行这个操作仍然是正确的Task.Run,那么我对应该将哪个任务放在活动任务列表中有点困惑:

    var task = Task.Run(()=>ReadStream(token)); activeTasks.Add(task);

    或者

    Task.Run(()=>{var task = ReadStream(token); activeTasks.Add(task);});

c#
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2021-12-06 20:14:10 +0000 UTC

将异步操作的进度输出到辅助窗口

  • 1

有一种从文件加载数据的方法。它通过调用事件来报告其进度OnFileLoad

    public Task UploadDataAsync()
    {
        return Task.Run(() =>
        {
            ...
            if (string.IsNullOrEmpty(FilePath))
            {
                OnFileLoading?.Invoke($"Error while loading: Path is empty");
                ...
                throw new Exception("Path is emprty");
            }

            if (!File.Exists(FilePath))
            {
                OnFileLoading?.Invoke($"Error while loading: File not found");
                ...
                throw new Exception("File not found");
            }

            OnFileLoading?.Invoke($"Start loading from '{FilePath}'");
            ...
            OnFileLoading?.Invoke("Loaded first line");
            OnFileLoading?.Invoke("Loaded second line");
            ...
            OnFileLoading?.Invoke("Loaded n line");
            ...
            OnFileLoading?.Invoke("Loading completed");
        });            
    }

主窗口类有一个用于单击“打开”按钮的事件处理程序。它会创建一个新窗口,显示从文件加载数据的进度。

    public async void OpenFileClick(object sender, RoutedEventArgs e)
    {
        try
        {
            var dataProvider = IocContainer.GetService<IDataProvider>();
            LoadingDataStatusWindow loadingDataStatusWindow = new LoadingDataStatusWindow();
            dataProvider.OnFileLoad = loadingDataStatusWindow.UpdateLoadingStatus;
            loadingDataStatusWindow.Show();
            dataProvider.FilePath = AppGlobalSettings.DataFilePath;
            await dataProvider.UploadDataAsync();
            items = dataProvider.CircuitItems;
            CircuitItemDataGrid.ItemsSource = dataProvider.CircuitItems;
        }
        catch(Exception ex)
        {
            LogUtility.LogError(ex);
        }
    }

窗口进度显示方法LoadingDataStatusWindow:

    public void UpdateLoadingStatus(string currentRow)
    {            
        StatusTextBox.Text += currentRow + Environment.NewLine;          
    }

尝试加载数据时,会发生错误,指示线程正在尝试访问另一个线程拥有的对象。StatusTextBox我试图通过向via添加文本来修复它Dispatcher。但这并没有帮助。

在这种情况下,如何通过异步数据加载将进度输出组织到第二个窗口,使其不会挂起 GUI?

c#
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-06-19 21:34:09 +0000 UTC

查看 VS Code 扩展时的错误

  • 0

按名称搜索分机时,会显示一个列表。我尝试单击任何查看 - 选项卡立即打开和关闭,出现错误。以下是开发人员工具中的输出:

在此处输入图像描述

重新安装编辑器什么也没做。以前,一切正常,成功查看扩展并安装它们。帮助解决问题。

visual-studio-code
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-04-13 20:00:22 +0000 UTC

将块设置为父级中剩余的高度

  • 0

body它需要我100vh。在页面的顶部有一个nav需要它的高度。如何设置块的高度mainContainer,使其将高度带到最后body(其中是否有足够的内容,是不是,或者它是否像屏幕截图中那样溢出)并且不超出它?例如,如果您设置,max-height: 100%那么由于存在nav. 屏幕截图以全高显示页面body。使用的类来自 Bootstrap 4。

在此处输入图像描述

<body class="bg-darkness vh-100 d-flex flex-column pb-lg-4">
  <nav class="navbar navbar-dark bg-dark">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Logo</a>
    </div>
  </nav>
  <div id="mainContainer" class="container-fluid container-lg pt-lg-2 flex-grow-1">
    <div class="row h-100">
      <div id="openedDialogContainer" class="col-12 col-sm-12 col-md-12 col-lg-8 h-100 bg-dark text-white p-0 d-flex flex-column justify-content-between">
        <div class="dialogInfo text-center pt-2 pb-1 border-bottom">
          <div class="dialogInfoTitle">Mustafa</div>
          <div class="dialogInfoStatus status">online</div>
        </div>
        <div class="pt-2 pb-2 container-lg h-100 y-scroll">
          <div class="messageContainer">
            <div class="message bg-white text-dark px-2 py-1 rounded d-inline-block">
              <div class="messageText">Hello!</div>
              <div class="messageStatus"></div>
            </div>
          </div>
          <div class="messageContainer mt-2 overflow-hidden">
            <div class="message bg-white text-dark px-2 py-1 w-75 rounded d-inline-block float-right">
              <div class="messageText text-break">Hello!HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello</div>
              <div class="messageStatus float-right">
                <svg class="bi bi-check-all" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                    <path fill-rule="evenodd" d="" clip-rule="evenodd"/>
                    <path d=""/>
                 </svg>
              </div>
            </div>
          </div>
        </div>
        <div class="container-lg">
           <div class="row p-2">
              <input type="text" class="form-control col col-sm col-md col-lg">
              <button class="btn col-auto col-sm-auto col-md-auto col-lg-auto">
                 <svg class="bi bi-triangle rotate invert" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                    <path fill-rule="evenodd" d="" clip-rule="evenodd" />
                 </svg>
              </button>
           </div>
        </div>         
     </div>
</body>

html
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-03-30 15:06:35 +0000 UTC

序列化对象列表

  • 1

ExcelStylesheet 类有一个对象,要序列化为 JSON。

public class ExcelStylesheet
{        
    public Dictionary<int, uint> CellFormatIndexes { get; set; }        
    public List<Font> Fonts { get; set; }        
    public List<CellFormat> CellFormats { get; set; }        
    public List<Fill> Fills { get; set; }        
    public List<Border> Borders { get; set; }
}

我正在尝试序列化到文件。

string json = JsonConvert.SerializeObject(stylesheet);
File.WriteAllText(filePath, json);

在输出我得到:

{"CellFormatIndexes": {"0": 9,"1": 10},"Fonts": [[[],[]],[[],[],[]]],"CellFormats": [[[]],[[]]],"Fills": [[]],"Borders": [[]]}

为什么要以这种方式序列化对象列表以及如何进行正常序列化?

使用的库:Newtonsoft.Json. 来自库类对象的列表DocumentFormat.OpenXml

c#
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-03-05 23:55:47 +0000 UTC

模块化方法 - 如何在模块内设置或更改变量?

  • 3

该模块有一个变量 - 存储退出按钮。在方法 init中,我尝试对其进行初始化,以便在此模块的其他方法中使用它,并在将来通过将其作为对象的字段返回来提供访问它的机会。但是,即使在调用该方法后该值logoutBtn仍然存在。undefinedinit

如何设置/更改模块内的变量,我的方法有什么不正确之处?

var myModule = (function () {    
var logoutBtn;    

var init = function () {             
    logoutBtn = document.getElementById("logoutButton");                
};   

...

return {
    init: init,
    ...    
    logoutButton: logoutBtn,
    ...
};
})();
javascript
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-12-19 15:33:59 +0000 UTC

依赖注入创建不同类型的实例

  • 2

我有 JWT 服务

public class JwtService : IJwtService
{
    private IDistributedCache cache;
    private IHttpContextAccessor httpContext;
    private IOptions<JwtOptions> jwtOptions;
    private MyContext context;
    private ILogger<JwtService> logger;

    public JwtService(MyContext context, IDistributedCache cache,
        IHttpContextAccessor httpContext, IOptions<JwtOptions> jwtOptions, ILogger<JwtService> logger)
    {
        this.cache = cache;
        this.httpContext = httpContext;
        this.jwtOptions = jwtOptions;
        this.context = context;
        this.logger = logger;
    }

    private string GetCurrentJwtString()
    {            
        StringValues header = httpContext.HttpContext.Request.Headers["authorization"];            
        return StringValues.IsNullOrEmpty(header) ? string.Empty : header.Single().Split(" ").Last();
    }

    public async Task<bool> IsActiveCurrentJwtAsync()
    {
        return await IsActiveJwtAsync(GetCurrentJwtString());
    }

    public async Task DeactivateCurrentJwtAsync()
    {            
        await DeactivateJwtAsync(GetCurrentJwtString());
    }

    public async Task DeactivateJwtAsync(string token)
    {                      
        await cache.SetStringAsync(token, "diactivated", new DistributedCacheEntryOptions()
        {
            AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(jwtOptions.Value.ExpiryMinutes)
        });                           
    }               

    public async Task<bool> IsActiveJwtAsync(string token)
    {                              
        return await cache.GetStringAsync(token) == null;
    }   

并且项目中有两个地方与这个服务交互:

第一的。在用户控制器中,当我注销帐户时,我会调用 deactivate token 方法,该方法只是缓存令牌。

[Authorize]
[Route("api/[controller]/[action]")]
[ApiController]
public class UserController : Controller
{
    IJwtService jwtServ;
    IUserService userServ;
    public UserController(IJwtService jwtServ, IUserService userServ)
    {
        this.jwtServ = jwtServ;
        this.userServ = userServ;
    }        

    [ActionName("Logout")]
    public async Task Logout()
    {
        await jwtServ.DeactivateCurrentJwtAsync();
    }
}

第二:在身份验证设置的 Startup 类中,验证令牌后,我检查它是否在缓存中。

services.AddDistributedRedisCache(option =>
        {
            option.Configuration = Configuration["Redis:Address"];
            option.InstanceName = "maelstorm";
        });

services
        .AddAuthentication(options => {
            options.DefaultAuthenticateScheme = jwtSchemeName;
            options.DefaultChallengeScheme = jwtSchemeName;                                           
        })
        .AddJwtBearer(jwtSchemeName, jwtBearerOptions => {                    
            jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
            {                        
                ValidateIssuerSigningKey = true,
                IssuerSigningKey = signingDecodingKey.GetKey(),
                TokenDecryptionKey = encryptingDecodingKey.GetKey(),

                ValidateIssuer = true,
                ValidIssuer = Configuration["Jwt:Issuer"],
                ValidateAudience = true,
                ValidAudience = Configuration["Jwt:Audience"],
                ValidateLifetime = true,
                ClockSkew = TimeSpan.FromSeconds(5)                        
            };                    
            var servProvider = services.BuildServiceProvider();
            var jwtService = servProvider.GetService<IJwtService>();
            jwtBearerOptions.Events = new JwtBearerEvents
            {                            
                OnAuthenticationFailed = context =>
                {                            
                    if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
                    {
                        context.Response.Headers.Add("Token-Expired", "true");
                    }                                                        
                    return Task.CompletedTask;                            
                },
                OnTokenValidated = async context =>
                {                            
                    if(! await jwtService.IsActiveCurrentJwtAsync())
                    {
                        context.Fail("Token is not active");                                                                                      
                    }                                    
                }                                                                       
            };

问题是,在第一种情况下,JWTService 中的缓存变量是类型Microsoft.Extensions.Caching.Distributed.MemoryDistributedCache,而在第二种情况下是Microsoft.Extensions.Caching.Redis.RedisCachе。事实证明,令牌停用方法将令牌写入一个缓存,而验证方法试图从另一个缓存中获取它,因此没有任何效果。为什么依赖注入会创建不同类型的实例?如何使只有 Redis 始终用作缓存?

c#
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-07-17 19:25:21 +0000 UTC

缺少请求标头

  • 1

我发送带有 Authorization 标头的请求。如果您通过自定义中间件查看请求数据,那么它就在那里

在此处输入图像描述

接下来是控制器。

[HttpGet]
[ActionName("GetUserData")]
public string GetUserData()
{
    return HttpContext.User.Claims.FirstOrDefault(x=>x.Type=="Email").Value;
}

然后标题和声明一起消失在某个地方

在此处输入图像描述

为什么请求数据在到达控制器之前就消失了?

配置方法如下所示:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {              
        app.UseHsts();
    }
    app.UseAuthentication();
    //MyMiddleware в этом не причастен, пробовал его убирать
    app.UseMiddleware<MyMiddleware>();
    app.UseHttpsRedirection();
    app.UseMvc();
}
c#
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-07-11 00:40:57 +0000 UTC

将 json 添加到服务器响应

  • 3

有一个从数据库中获取的对象列表(一些数据)。我希望在访问站点时为客户端提供一个页面,并使用它以 json 格式提供此数据,以便将来使用 js 在页面上与它们进行交互。我读到您可以将其添加到服务器响应的正文中,但是 Response.Write() 方法需要一个字节数组,并且我没有找到有关如何将 json 转换为字节的信息。如何给客户一个带有 json 的页面?

    public IActionResult CheckFormulas(int categoryId)
    {
        // Данные, которые нужно передать в json 
        IEnumerable<Formula> formulas = _formServ.GetFormulasByCategoryId(categoryId);                      
        return View("CheckFormulas");
    }
c#
  • 2 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-06-21 05:48:14 +0000 UTC

Web 应用程序找不到视图

  • 2

这只是我的网站发布的某种麻烦。一点背景: 无效的 web.config 配置文件

使用 dotnet eshop.dll 命令运行直接发布的 Web 应用程序并对其进行访问时,将以下错误写入控制台:

失败:Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0] 发生未处理的异常:找不到布局视图“/Views/Shared/Layout.cshtml”。搜索了以下位置:/Views/Shared/Layout.cshtml

发布站点的文件夹中的文件列表在此处输入图像描述

如果存在带有预编译视图的库,为什么会出现此错误?

веб-программирование
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-04-23 03:01:48 +0000 UTC

在 JavaScript 中反序列化 JSON 对象

  • 1

需要获取 Man 类的对象列表

public class Man
{
    public int Id { get; set; }
    public string Firstname { get; set; }
    public string Secondname { get; set; }
    public int Age { get; set; }
}

向服务器发送请求

$.ajax({
    url: url,
    type: "POST",
    data: {
        "count": count
    },
    dataType: "json"
})

在控制器方法中,我形成一个对象数组并将其发送给客户端

for (int i = 0; i < dif; i++)
{
    mans[i] = await manContext.Mans.FirstOrDefaultAsync(m => m.Id == mansCount - dif + i);
}
return Json(mans);

如何使用 JS 从 JSON 中获取 Man 对象的字段值(姓名、年龄等)?

javascript
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-02-20 05:01:30 +0000 UTC

样式表未完全加载

  • 0

在 Visual Studio 中启动应用程序时,页面正常显示,一切正常。发布应用时,不是加载整个 .css 文件,而是 81 行中只有 54 行

在此处输入图像描述

为什么一段代码被忽略,如何解决?

css
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-02-18 16:09:19 +0000 UTC

Html 元素不显示

  • 0

有一个文本存储在数据库中,它包含一个链接。为什么浏览器不显示?在此处输入图像描述

<div id="publicationContent">
    <div id="publicationName">
        @Model.Tittle
    </div>
    <div id="publicationText">
        @Model.Text
    </div>
</div>
html
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-01-27 22:35:18 +0000 UTC

更改用户角色时如何立即重新读取它们

  • 3

只有具有“管理员”角色的用户才能访问控制器:

namespace ASPMVC.Controllers
{
    [Authorize(Roles ="admin")]   
    public class AirplaneController : Controller
    {
    }
}

我正在使用没有角色的帐户,应用程序不会让我:在此处输入图像描述

安装“管理员”角色后:在此处输入图像描述

但是应用程序再次拒绝访问: 在此处输入图像描述 如果您重新启动应用程序,则会出现访问权限。问题:如何让角色发生变化时,用户无需重新启动应用程序就可以访问控制器?

RoleController中改变用户角色的方法:

    [HttpPost]
    public async Task<IActionResult> Edit(string userId, List<string> roles)
    {            
        UserDop userDop = await userManager.FindByIdAsync(userId);
        if (userDop != null)
        {
            var userRoles = await userManager.GetRolesAsync(userDop);
            var allRoles = roleManager.Roles.ToList();
            var addedRoles = roles.Except(userRoles);
            var removedRoles = userRoles.Except(roles);

            await userManager.AddToRolesAsync(userDop, addedRoles);
            await userManager.RemoveFromRolesAsync(userDop, removedRoles);
            return RedirectToAction("UserList");
        }
        return NotFound();
    }
c#
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-01-27 02:10:54 +0000 UTC

Web 应用程序数据验证

  • 2

我开始学习 ASP.NET 并开始进行数据验证,这可以在客户端和服务器端完成。对用户输入的数据在哪一侧进行验证比较好,还是两边同时检查?应该在客户端验证哪些数据和应该在服务器端验证哪些数据之间是否有区别?

веб-программирование
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-01-20 04:38:32 +0000 UTC

异步操作已被取消

  • 1

我正在尝试发送一封电子邮件(代码取自Microsoft文档),但操作被取消并且邮件没有收到邮件。帮助解决问题。

static bool mailSent = false;
    private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
    {

        String token = (string)e.UserState;

        if (e.Cancelled)
        {
            Console.WriteLine("[{0}] Send canceled.", token);
        }
        if (e.Error != null)
        {
            Console.WriteLine("[{0}] {1}", token, e.Error.ToString());
        }
        else
        {
            Console.WriteLine("Message sent.");
        }
        mailSent = true;
    }


    public static void SendMessage()
    {           
        SmtpClient client = new SmtpClient();
        client.Host = "smtp.gmail.com";
        client.Port = 465;
        client.UseDefaultCredentials = false;
        client.Credentials = new NetworkCredential(mailFrom, password);

        MailAddress from = new MailAddress(mailFrom,"saturn",System.Text.Encoding.UTF8);

        MailAddress to = new MailAddress(mailTo);

        MailMessage message = new MailMessage(from, to);
        message.Body = "This is a test e-mail message sent by an application. ";

        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.Subject = "test message 1";
        message.SubjectEncoding = System.Text.Encoding.UTF8;

        client.SendCompleted += new
        SendCompletedEventHandler(SendCompletedCallback);

        string userState = "test message1";
        client.SendAsync(message, userState);            

        if (mailSent == false)
        {
            client.SendAsyncCancel();
        }

        message.Dispose();
    }

在此处输入图像描述

c#
  • 2 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-01-20 00:15:52 +0000 UTC

从页面中删除 ASP MVC 面板

  • 1

如何删除此面板? 在此处输入图像描述

asp.net
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-01-11 03:06:37 +0000 UTC

安装 Visual Studio 时出错

  • 0

安装 VS2017 时:

安装 Microsoft.VisualStudio.AspNet45.Feature 失败

安装了 MSBuildTools 2015,没有帮助。安装了 MSBuildTools 2017,得到了同样的错误。如何解决问题?

无法安装包“Microsoft.VisualStudio.AspNet45.Feature,version=15.0.27128.1”。搜索 URL https://aka.ms/VSSetupErrorReports?q=PackageId=Microsoft.VisualStudio.AspNet45.Feature;PackageAction=Install;ReturnCode=87 详细信息 命令完成:"C:\Windows\system32\dism.exe" /online /quiet /norestart /Enable-Feature /FeatureName:"netfx4extended-aspnet45" /All /logPath:"C:\Users\lin\AppData\Local \Temp\dd_setup_20180110214954_086_Microsoft.VisualStudio.AspNet45.Feature.log” 返回代码:87 返回代码详细信息:未指定文件路径。C:\Users\lin\AppData\Local\Temp\dd_setup_20180110214954_086_Microsoft.VisualStudio.AspNet45.Feature.log 受影响的 ASP.NET 工作负载和 Web 应用程序开发 (Microsoft.VisualStudio.Workload.NetWeb,version=15.0.27102.0) 跨平台。 NET Core 开发 (Microsoft.VisualStudio.Workload.NetCoreTools,version=15.0.27102.0) .NET 桌面开发 (Microsoft.VisualStudio.

visual-studio
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-01-04 23:19:22 +0000 UTC

Java中的后端

  • -1

一天中的好时光。我开始学习后端,但 YouTube 上的视频课程还没有完全完成,我还有几个问题。“老师”只使用一个类“MyServlet.java”完成所有课程,该类继承自 HTTPServlet 并具有两个 GET 和 POST 方法(这些方法很清楚)。比如注册的时候,用户传递一些数据

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Регистрация</title>
</head>
<body>	
	<form method = "POST" action ="MyServlet">
	Имя<input type = "text" name = "name">
	Возраст<input type ="text" name = "age">
	Электронная почта<input type = "text" name = "email">
	<input type = "submit" value = "Зарегистрировать">
	</form>
</body>
</html>

进一步,在POST方法中,这些参数被取走,用户被注册

String name = request.getParameter("name");
String age = request.getParameter("age");
String email = request.getParameter("email");

如果我们想从另一个 html 页面传递完全不同的参数呢?每个页面是否可以用自己的GET和POST编写自己的java类并在html中指定类和方法?

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Информация пользователя</title>
</head>
<body>
	<form method = "METHOD" action = "CLASS">
	.....
	</form>
</body>
</html>

java
  • 1 个回答
  • 10 Views
Martin Hope
ZOOM SMASH
Asked: 2020-10-31 02:50:00 +0000 UTC

在 Unity 中更改对象材质

  • 0

我正在尝试通过代码更改对象的材质

 if (MoveToPoint(point[stage]))
    {
        stage = stage == 1 ? 0 : 1;
        if (on_x)
            transform.localScale = new Vector3(-transform.localScale.x, 1, 0.032f);
        else
        {
            gameObject.GetComponent<MeshRenderer>().materials[0] = materials[stage];                                   
        }

    }

在这种情况下,尽管满足条件,但对象的材质不会改变。在更改材质(在其他情况下)之前尝试禁用 Animator 和 NavMeshAgent,但没有帮助。问题是什么?(下面是材质数组和标准物体材质)在此处输入图像描述在此处输入图像描述

在此处输入图像描述

c#
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5