我的Spring Dispatcher servlet url-pattern是/*(正如Spring MVC REST建议的那样)
现在所有的请求都由这个Servlet解决了.甚至CSS/JS/Images也可以通过servlet解决和处理.
所以,Spring MVC试图找到控制器.. :(
如何绕过这个?有没有任何标准的方法解决这个问题?
&不想将url-pattern更改为/ rest/*(因此,/ css /或/ js等访问其他静态资源)
java servlets spring-mvc url-pattern tuckey-urlrewrite-filter
也许有人可以帮助/解释我,如何urls.py在Django中为Flask 创建文件?
main.py - 主项目文件.它仅包括app runner(app.run()).urls.py位于同一目录,需要提供视图views.py.我需要在简单的 node.js 中等效于以下 express.js 代码,我可以在中间件中使用它。我需要根据 url 进行一些检查,并希望在自定义中间件中进行。
app.get "/api/users/:username", (req,res) ->
req.params.username
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有以下代码,
app.use (req,res,next)->
if url.parse(req.url,true).pathname is '/api/users/:username' #this wont be true as in the link there will be a actual username not ":username"
#my custom check that I want to apply
Run Code Online (Sandbox Code Playgroud) 下面是我的控制器、web xml 和使用 spring 形式的 jsp 页面。
控制器
@Controller
@RequestMapping(value = {"/*", "/login"})
public class HelloWorldController {
@RequestMapping(method = RequestMethod.GET)
public String helloWorld(final Model model) {
model.addAttribute("bodyPage", "body.jsp");
User user = new User();
Address address = new Address();
user.setAddress(address);
model.addAttribute("myUser", user);
System.out.println("hello world");
return "login";
}
@RequestMapping(value = "/submitDetails", method = RequestMethod.POST)
public ModelAndView submitDetais(final Object command) {
System.out.println("inside submitDetais ");
User user = (User) command;
return new ModelAndView("result", "user", user);
}
}
Run Code Online (Sandbox Code Playgroud)
网页 XML
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> …Run Code Online (Sandbox Code Playgroud) 在基于纯客户端的 Web 应用程序中,我需要显示有时不存在的背景图像。当特定的 URL 模式返回 404 错误时,有没有办法“强制”Apache 提供图像?
可能返回 404 的 URL 模式是:
http://host/assets/user-images/xxxxx.jpg
我想在哪里提供图像:
http://host/assets/user-images/default.jpg
笔记:
我已经使用了 .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud) 我正在使用appengine,似乎在使用url路由时遇到了一些问题
我的web.xml
<servlet>
<servlet-name>ViewServlet</servlet-name>
<jsp-file>viewdata.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>ViewServlet</servlet-name>
<url-pattern>/view/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>default.html</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)
当我在本地机器上测试时,重定向工作正常.当我尝试导航到http:// myurl/view /它无限重定向到上传到appengine
http://myurl/view/default.html/default.html ...
这是在web.xml中重定向的正确方法吗?我在这里错过了一些东西.它在本地机器上运行良好.上传到gae时进入无限循环.任何帮助,将不胜感激...
如何将从特定模式开始的所有URL重定向到另一个?
描述:
我希望能够重定向如下:
/pattern1/step1/ to /pattern2/step1/
/pattern1/step2/ to /pattern2/step2/
/pattern1/continue/ to /pattern2/continue/
Run Code Online (Sandbox Code Playgroud)
在Django URL模式中执行此操作的最简单方法是什么?
我在Django视图上有此错误:
TypeError at /web/host/1/
decorator() got an unexpected keyword argument 'host_id'
Request Method: GET
Request URL: http://127.0.0.1:8000/web/host/1/edit
Django Version: 1.10.4
Exception Type: TypeError
Exception Value:
decorator() got an unexpected keyword argument 'host_id'
Run Code Online (Sandbox Code Playgroud)
urlpatterns是:
url(r'^host/(?P<host_id>[0-9]+)$', host, name='host'),
Run Code Online (Sandbox Code Playgroud)
视图功能是:
@check_login
def host(request, host_id, *args, **kwargs):
h = Host()
# resultHost = h.get_host(host_id)
return render(request, 'web/host.html')
Run Code Online (Sandbox Code Playgroud)
check_login如下:
def check_login(f):
"""verify if user login"""
def decorator(request):
if request.session.get('user', None):
return f(request)
else:
return HttpResponseRedirect(reverse("web:login"))
return decorator
Run Code Online (Sandbox Code Playgroud)
如果我使用不带参数“ host_id”的url和不带host_id的宿主函数,则该程序将运行完美。
所以有什么问题?谢谢。
我已经阅读了很多例子,虽然我似乎有一个'确切'的副本,所以我无法弄清楚为什么我的过滤器将导航到/login而不是/restricted/*.我已经尝试了两个注释(如下例所示)和XML来定义WebFilter.
Webfilter
@WebFilter(filterName = "AuthenticationFilter", servletNames = { "Faces Servlet" }, urlPatterns = { "/restricted/*" } )
public class AuthenticationFilter implements Filter {
@Inject
private SessionManager sessionManager;
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
System.out.println("Active AuthenticationFilter");
if (sessionManager.getUser() == null) {
((HttpServletResponse) response).sendRedirect("/login");
}
else {
chain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
}
Run Code Online (Sandbox Code Playgroud)
web.xml中
<servlet>
<servlet-name>Faces Servlet</servlet-name> …Run Code Online (Sandbox Code Playgroud) 我用的时候
http.HandleFunc("/", serveRest) //serveRest is the method to handle request
http.ListenAndServe("localhost:4000", nil)
Run Code Online (Sandbox Code Playgroud)
它将接受所有请求"/".如何限制它仅用于"localhost:4000"代替每个地址"localhost:4000/*"?
你们可以给我一个很好的Go教程吗?
url-pattern ×10
django ×3
java ×3
servlets ×3
python ×2
spring-mvc ×2
.htaccess ×1
apache ×1
django-urls ×1
express ×1
flask ×1
go ×1
http ×1
jakarta-ee ×1
jsf ×1
node.js ×1
server ×1
web.xml ×1