Chrome 我的Java代码无法重定向- ERR_UNSAFE_REDIRECT

sqyvllje  于 2023-03-21  发布在  Go
关注(0)|答案(2)|浏览(294)

我又挣扎了一个小时来修东西,但我还是不能让它工作:
我有一个简单的程序,它从index.html中的注册表中获取信息,并将其添加到PostgreSQL数据库中。
当我点击注册,该程序的工作,并添加到数据库中的信息
问题是我无法让重定向起作用
我得到以下错误

This site can’t be reachedThe webpage at http://localhost:8081/register might be temporarily down or it may have moved permanently to a new web address.
ERR_UNSAFE_REDIRECT

我的java代码如下:

  • 这是注册控制器类
package ro.fortech.guardianangel.registration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;

@RestController
@RequestMapping("/register")
public class RegistrationController {

    @Autowired
    private UserRepository userRepository;

    @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public RedirectView registerSubmit(Users users) {
        Users user = userRepository.save(users);
        return new RedirectView("file:///C:/Users/timis/Desktop/programare/curs%20java/Proiect/frontend/index.html#!");
    }
}
  • 这是“用户”类
package ro.fortech.guardianangel.registration;

import lombok.Data;
import javax.persistence.*;

@Entity
@Table(name = "users")
@Data
public class Users {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    private String email;
    private String password;
}
  • 这是UserRepository接口
package ro.fortech.guardianangel.registration;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<Users, Integer> {}

所以基本上在我点击提交后,我希望我的浏览器带我回到:

file:///C:/Users/timis/Desktop/programare/curs%20java/Proiect/frontend/index.html
dluptydi

dluptydi1#

任何正常的网页浏览器都会拒绝从http:// URL重定向到file:// URL的尝试。这是出于安全原因,并且长期以来都是如此,另请参阅:
https://security.stackexchange.com/questions/18685/are-there-any-know-browsers-that-support-file-url-redirection
你必须把那个文件的内容放到某个Web服务器上,然后重定向到那个服务器。

o0lyfsai

o0lyfsai2#

@teapot418,谢谢你的回答,我不知道。我已经移动了github上的文件,非常感谢

相关问题