我正在开发一个需要访问Geoserver的网络地图应用程序,我安装了wampserver来加载我的php和html / js文件。
我可以使用jsonp格式从Geoserver访问数据,但由于CORS策略,我无法发送添加/更新/删除操作的WFS-T请求。
我试图在网络上找到许多解决方案,这里是stackoverflow,但我遇到了同样的问题
http://localhost:8080/geoserver/wfs [HTTP / 1.1 403禁止3毫秒]
Blocage d'unerequêtemulti-origines(Cross-Origin Request):la politique«same Origin»ne permet pas de consulter la ressourcedistantesituéesurhttp://localhost:8080/geoserver/wfs。 Raison:l'en-têteCORS«Access-Control-Allow-Origin»est manquant。
表示由于缺少Access-Control-Allow-Origin标头而导致请求被阻止。
检查apache中的headers_module并将以下行添加到C:\ wamp64 \ bin \ apache \ apache2.4.17 \ conf
中的httpd.conf文件中<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</IfModule>
这是来自Apache方面,关于Geoserver Side如何启用它?
答案 0 :(得分:1)
在library(shiny)
ui<-fluidPage(
sidebarPanel(
fluidRow(
selectInput("INPUT", label="Input:" ,choices=list("",1,2,3,4,5,6,7)),
selectInput("NINPT", label="Name:", choices=list("","Area","length","width")),
selectInput("COLOUR", label="Color:", choices=list("","black","white","red","green","blue","brown","yellow")),
actionButton("ADDIN",label="add"))),
mainPanel(fluidPage(
fluidRow(tableOutput("DF_table"),tableOutput("check")))))
server1 <- function(session,input, output) {
counter <- reactiveValues(countervalue = 0) # I tried make a reactive value, and pasted in id name for each data.frame
observeEvent(input$ADDIN,{
counter$countervalue <- counter$countervalue + 1 })
DFrame<-eventReactive(input$ADDIN,{
# in this case, after I select of the three "input" options, when clicking add,
# it should generate a data.frame. So each time I clicked it would generate a new data.frame.
# just use the "rbind.data.frame" command to join the data.frame()
eval(parse(text=paste("df",as.numeric(input$INPUT),"<-data.frame(iten=",as.numeric(input$INPUT),',color="',input$COLOUR,'",name="',input$NINPT,'")',sep="")))
eval(parse(text=paste(c("rbind.data.frame(",rep("",counter$countervalue-1)),"df",1:counter$countervalue,c(rep(",",counter$countervalue-1),")"),sep="")))
})
output$DF_table<-renderTable({DFrame()})
#output$check<-renderTable({ data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT,add=counter$countervalue)})
}
shinyApp(ui,server1)
# but it can not find the data.frame : Warning: Error in rbind.data.frame: object 'df1' not found!
#---------------------------------------------------------------------------------------
# I tried make a reactive value, and add a data.frame enpty
server2 <- function(session,input, output) {
DT<-reactiveValues(DT=NULL)
observeEvent(input$ADDIN,{
DT$DT<-data.frame(iten=NULL,cor=NULL,nome=NULL)
})
# after that, join'd a empty data.frame , and new data.frame, using "rbind.data.frame" when press "actionButton"
DFrame<-eventReactive(input$ADDIN,{
rbind.data.frame(DT$DT,data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT))
})
output$DF_table<-renderTable({DFrame()})
#output$check<-renderTable({ data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT)})
}
shinyApp(ui,server2)
#---------------------------------------------------------------------------------------
# I tried add row in data.frame empty
server3 <- function(session,input, output) {
DT<-reactiveValues(DT=NULL)
observeEvent(input$ADDIN,{
DT$DT<-data.frame(iten="",color="",name="")
})
eventReactive(input$ADDIN,{
DT$DT[as.numeric(input$INPUT),]<-data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT)
})
output$DF_table<-renderTable({DT$DT})
#output$check<-renderTable({ data.frame(iten=as.numeric(input$INPUT),color=input$COLOUR,name=input$NINPT)})
}
shinyApp(ui,server3)
目录中打开web.xml
文件,然后搜索CORS。取消注释2个CORS过滤器部分的注释,然后重新启动geoserver。